Package 'proBatch'

Title: Tools for Diagnostics and Corrections of Batch Effects in Proteomics
Description: These tools facilitate batch effects analysis and correction in high-throughput experiments. It was developed primarily for mass-spectrometry proteomics (DIA/SWATH), but could also be applicable to most omic data with minor adaptations. The package contains functions for diagnostics (proteome/genome-wide and feature-level), correction (normalization and batch effects correction) and quality control. Non-linear fitting based approaches were also included to deal with complex, mass spectrometry-specific signal drifts.
Authors: Jelena Cuklina [aut], Chloe H. Lee [aut], Patrick Pedrioli [aut], Olga Zolotareva [aut], Yuliya Burankova [cre]
Maintainer: Yuliya Burankova <[email protected]>
License: GPL-3
Version: 2.1.3
Built: 2026-10-31 10:16:46 UTC
Source: https://github.com/bioc/proBatch

Help Index


Subset ProBatchFeatures objects without dropping metadata.

Description

Ensures the [ method returns a ProBatchFeatures instance so the subclass-specific slots remain available after subsetting.

Usage

## S4 method for signature 'ProBatchFeatures,ANY,ANY,ANY'
x[i, j, k, ..., drop = TRUE]

Arguments

x

A ProBatchFeatures object.

i

Row indices passed to the underlying QFeatures subset.

j

Column indices passed to the underlying QFeatures subset.

k

Assay indices passed to the underlying QFeatures subset.

...

Additional arguments forwarded to the next method.

drop

Logical flag controlling dimension dropping; defaults to TRUE.

Value

A ProBatchFeatures object containing the requested subset.


Coerce a QFeatures object into ProBatchFeatures

Description

Wraps an existing QFeatures instance into the ProBatchFeatures subclass, initializing the operation log and optional assay renaming when a single assay is present.

Usage

as_ProBatchFeatures(
  object,
  level = "feature",
  pipeline = "raw",
  sample_id_name = NULL
)

Arguments

object

A QFeatures object to wrap.

level

Character scalar used as the default level when renaming a single assay.

pipeline

Character scalar used as the default pipeline when renaming a single assay.

sample_id_name

Optional character scalar indicating the sample ID column name in colData.

Value

A ProBatchFeatures object containing the same assays as object.

Examples

if (requireNamespace("QFeatures", quietly = TRUE)) {
    data(example_proteome_matrix, package = "proBatch")
    data(example_sample_annotation, package = "proBatch")
    sample_order <- match(
        colnames(example_proteome_matrix),
        example_sample_annotation$FullRunName
    )
    cd <- S4Vectors::DataFrame(
        example_sample_annotation[sample_order, , drop = FALSE]
    )
    rownames(cd) <- colnames(example_proteome_matrix)
    se <- SummarizedExperiment::SummarizedExperiment(
        assays = list(intensity = example_proteome_matrix),
        colData = cd
    )
    qf <- QFeatures::QFeatures(
        experiments = list(peptideRaw = se),
        colData = cd
    )
    as_ProBatchFeatures(qf, level = "peptide")
}

Calculate CV distribution for each feature

Description

Calculate CV distribution for each feature

Usage

calculate_feature_CV(
  df_long,
  sample_annotation = NULL,
  feature_id_col = "peptide_group_label",
  sample_id_col = "FullRunName",
  measure_col = "Intensity",
  batch_col = NULL,
  biospecimen_id_col = NULL,
  unlog = TRUE,
  log_base = 2,
  offset = 0,
  pbf_name = NULL
)

Arguments

df_long

data frame where each row is a single feature in a single sample, or a 'ProBatchFeatures' object.

sample_annotation

data frame with sample-level metadata. For data frame input, this is optional when the requested batch and biospecimen columns are already present in 'df_long'; otherwise it supplies those columns. For 'ProBatchFeatures' input, omitted annotation defaults to 'as.data.frame(colData(df_long))'.

feature_id_col

name of the column with feature/gene/peptide/protein ID used in the long format representation df_long. In the wide formatted representation data_matrix this corresponds to the row names.

sample_id_col

name of the column in sample_annotation table, where the filenames (colnames of the data_matrix are found).

measure_col

if df_long is among the parameters, it is the column with expression/abundance/intensity; otherwise, it is used internally for consistency.

batch_col

column in sample_annotation that should be used for batch comparison (or other, non-batch factor to be mapped to color in plots).

biospecimen_id_col

column in sample_annotation that defines a unique bio ID, which is usually a combination of conditions or groups. Tip: if such ID is absent, but can be defined from several columns, create new biospecimen_id column

unlog

(logical) whether to reverse log transformation of the original data

log_base

base of the logarithm for transformation

offset

small positive number to prevent 0 conversion to -Inf

pbf_name

Assay name used when 'df_long' is a 'ProBatchFeatures' object. If 'NULL', [pb_current_assay()] is used.

Value

data frame with replicate-level CV values:

  • CV_total: per feature_id_col and biospecimen_id_col (and per Step, if present),

  • CV_perBatch: additionally stratified by batch_col when provided.

Examples

data(
    list = c("example_sample_annotation", "example_proteome"),
    package = "proBatch"
)
CV_df <- calculate_feature_CV(example_proteome,
    sample_annotation = example_sample_annotation,
    measure_col = "Intensity",
    batch_col = "MS_batch",
    biospecimen_id_col = "EarTag"
)

Calculate peptide correlation between and within peptides of one protein

Description

Calculate peptide correlation between and within peptides of one protein

Usage

calculate_peptide_corr_distr(
  data_matrix,
  peptide_annotation,
  protein_col = "ProteinName",
  feature_id_col = "peptide_group_label",
  pbf_name = NULL
)

Arguments

data_matrix

features (in rows) vs samples (in columns) matrix, with feature IDs in rownames and file/sample names as colnames, or a 'ProBatchFeatures' object. When 'data_matrix' is a 'ProBatchFeatures' object, 'pbf_name' is used (or the current assay when 'pbf_name = NULL').

peptide_annotation

long format data frame with peptide ID and their corresponding protein and/or gene annotations. When 'data_matrix' is a matrix, this argument is required. When 'data_matrix' is a 'ProBatchFeatures' object and 'peptide_annotation' is not provided, rowData from the selected assay is used.

protein_col

column where protein names are specified

feature_id_col

name of the column with feature/gene/peptide/protein ID used in the long format representation df_long. In the wide formatted representation data_matrix this corresponds to the row names.

pbf_name

Assay name used when 'data_matrix' is a 'ProBatchFeatures' object. If 'NULL', [pb_current_assay()] is used.

Value

dataframe with peptide correlation coefficients that are suggested to use for plotting in plot_peptide_corr_distribution as plot_param:

Examples

data(
    list = c("example_peptide_annotation", "example_proteome_matrix"),
    package = "proBatch"
)
selected_genes <- c("BOVINE_A1ag", "BOVINE_FetuinB", "Cyfip1")
gene_filter <- example_peptide_annotation$Gene %in% selected_genes
peptides_ann <- example_peptide_annotation$peptide_group_label
selected_peptides <- peptides_ann[gene_filter]
matrix_test <- example_proteome_matrix[selected_peptides, ]
pep_annotation_sel <- example_peptide_annotation[gene_filter, ]
corr_distribution <- calculate_peptide_corr_distr(matrix_test,
    pep_annotation_sel,
    protein_col = "Gene"
)

Calculate variance distribution by variable

Description

Calculate variance distribution by variable

Usage

## Default S3 method:
calculate_PVCA(
  data_matrix,
  sample_annotation,
  feature_id_col = "peptide_group_label",
  sample_id_col = "FullRunName",
  factors_for_PVCA = c("MS_batch", "digestion_batch", "Diet", "Sex", "Strain"),
  pca_threshold = 0.6,
  variance_threshold = 0.01,
  fill_the_missing = -1,
  ...
)

## S3 method for class 'ProBatchFeatures'
calculate_PVCA(
  data_matrix,
  pbf_name = NULL,
  sample_annotation = NULL,
  feature_id_col = "peptide_group_label",
  sample_id_col = "FullRunName",
  ...
)

Arguments

data_matrix

features (in rows) vs samples (in columns) matrix, with feature IDs in rownames and file/sample names as colnames. See "example_proteome_matrix" for more details (to call the description, use help("example_proteome_matrix"))

sample_annotation

data frame with:

  1. sample_id_col (this can be repeated as row names)

  2. biological covariates

  3. technical covariates (batches etc)

. See help("example_sample_annotation")

feature_id_col

name of the column with feature/gene/peptide/protein ID used in the long format representation df_long. In the wide formatted representation data_matrix this corresponds to the row names.

sample_id_col

name of the column in sample_annotation table, where the filenames (colnames of the data_matrix are found).

factors_for_PVCA

vector of factors from sample_annotation, that are used in PVCA analysis

pca_threshold

the percentile value of the minimum amount of the variabilities that the selected principal components need to explain

variance_threshold

the percentile value of weight each of the factors needs to explain (the rest will be lumped together)

fill_the_missing

numeric value determining how missing values should be substituted. If NULL, features with missing values are excluded.

...

For ProBatchFeatures input, additional per-assay arguments forwarded to calculate_PVCA.default(). Unmatched arguments captured by the default method's own ... are currently ignored.

pbf_name

Assay name(s) used when data_matrix is a ProBatchFeatures.

Value

For matrix input, a data frame of Principal Variance Component weights. For ProBatchFeatures input, one selected assay returns that data frame and multiple assays return a named list of data frames.

Examples

data(
    list = c("example_proteome_matrix", "example_sample_annotation"),
    package = "proBatch"
)
matrix_test <- na.omit(example_proteome_matrix)[1:50, ]
pvca_df <- calculate_PVCA(matrix_test, example_sample_annotation,
    factors_for_PVCA = c(
        "MS_batch", "digestion_batch", "Diet", "Sex", "Strain"
    ),
    pca_threshold = .6, variance_threshold = .01, fill_the_missing = -1
)

Calculates correlation for all pairs of the samples in data matrix, labels as replicated/same_batch/unrelated in output columns (see "Value").

Description

Calculates correlation for all pairs of the samples in data matrix, labels as replicated/same_batch/unrelated in output columns (see "Value").

Usage

calculate_sample_corr_distr(
  data_matrix,
  sample_annotation,
  repeated_samples = NULL,
  biospecimen_id_col = "EarTag",
  sample_id_col = "FullRunName",
  batch_col = "MS_batch",
  pbf_name = NULL
)

Arguments

data_matrix

features (in rows) vs samples (in columns) matrix, with feature IDs in rownames and file/sample names as colnames, or a 'ProBatchFeatures' object. When 'data_matrix' is a 'ProBatchFeatures' object, 'pbf_name' is used (or the current assay when 'pbf_name = NULL').

sample_annotation

data frame with sample-level metadata. When 'data_matrix' is a matrix, this argument is required. When 'data_matrix' is a 'ProBatchFeatures' object and 'sample_annotation' is not provided, 'as.data.frame(colData(data_matrix))' is used.

repeated_samples

vector of sample IDs to evaluate, if NULL, all samples are taken into account for plotting

biospecimen_id_col

column in sample_annotation that defines a unique bio ID, which is usually a combination of conditions or groups. Tip: if such ID is absent, but can be defined from several columns, create new biospecimen_id column

sample_id_col

name of the column in sample_annotation table, where the filenames (colnames of the data_matrix are found).

batch_col

column in sample_annotation that should be used for batch comparison (or other, non-batch factor to be mapped to color in plots).

pbf_name

Assay name used when 'data_matrix' is a 'ProBatchFeatures' object. If 'NULL', [pb_current_assay()] is used.

Value

dataframe with the following columns, that are suggested to use for plotting in plot_sample_corr_distribution as plot_param:

  1. replicate

  2. batch_the_same

  3. batch_replicate

  4. batches

other columns are:

  1. sample_id_1 & sample_id_2, both generated from sample_id_col variable

  2. correlation - correlation of two corresponding samples

  3. batch_1 & batch_2 or analogous, created the same as sample_id_1

Examples

data(
    list = c("example_sample_annotation", "example_proteome_matrix"),
    package = "proBatch"
)
corr_distribution <- calculate_sample_corr_distr(
    data_matrix = example_proteome_matrix,
    sample_annotation = example_sample_annotation,
    batch_col = "MS_batch", biospecimen_id_col = "EarTag"
)

Center features per-batch by median/mean (unified)

Description

Centers each feature within each batch to the global location (median/mean) of that feature. Works for long-data frames and wide matrices.

Usage

center_feature_batch(
  x,
  sample_annotation = NULL,
  format = c("long", "wide"),
  stat = c("medians", "means"),
  sample_id_col = "FullRunName",
  batch_col = "MS_batch",
  feature_id_col = "peptide_group_label",
  measure_col = "Intensity",
  keep_all = "default",
  no_fit_imputed = TRUE,
  qual_col = NULL,
  qual_value = NULL
)

Arguments

x

Either a long data.frame or a numeric matrix (features in rows, samples in columns), depending on format.

sample_annotation

data frame with:

  1. sample_id_col (this can be repeated as row names)

  2. biological covariates

  3. technical covariates (batches etc)

. See help("example_sample_annotation")

format

One of "long" or "wide". "long" expects a data.frame with columns sample_id_col, feature_id_col, measure_col. "wide" expects a numeric matrix and uses matrix_to_long() / long_to_matrix().

stat

One of "medians" or "means". Aliases "median"/"mean" are accepted.

sample_id_col

name of the column in sample_annotation table, where the filenames (colnames of the data_matrix are found).

batch_col

column in sample_annotation that should be used for batch comparison (or other, non-batch factor to be mapped to color in plots).

feature_id_col

name of the column with feature/gene/peptide/protein ID used in the long format representation df_long. In the wide formatted representation data_matrix this corresponds to the row names.

measure_col

if df_long is among the parameters, it is the column with expression/abundance/intensity; otherwise, it is used internally for consistency.

keep_all

Passed to subset_keep_cols() for long format, ignored for wide.

no_fit_imputed

If TRUE and qual_col is provided, imputed values are masked during location estimation (original values remain unchanged).

qual_col, qual_value

Column and value that flag imputed entries.

Details

For "wide", conversion uses matrix_to_long() / long_to_matrix(). For "long", the function adds "preBatchCorr_[measure_col]" and the diagnostic columns:

  • for medians: median_batch, median_global, diff_medians

  • for means: mean_batch, mean_global, diff_means

Value

If format = "long", a data.frame; if format = "wide", a matrix.

Examples

# LONG
# Load necessary datasets
data(
    list = c("example_sample_annotation", "example_proteome"),
    package = "proBatch"
)
out_long <- center_feature_batch(
    x = example_proteome, sample_annotation = example_sample_annotation,
    format = "long", stat = "medians",
    sample_id_col = "FullRunName", batch_col = "MS_batch",
    feature_id_col = "peptide_group_label", measure_col = "Intensity",
    no_fit_imputed = FALSE
)

# WIDE
data(example_proteome_matrix, package = "proBatch")
out_wide <- center_feature_batch(
    x = example_proteome_matrix,
    sample_annotation = example_sample_annotation,
    format = "wide", stat = "means",
    sample_id_col = "FullRunName", batch_col = "MS_batch",
    feature_id_col = "peptide_group_label", measure_col = "Intensity",
    no_fit_imputed = FALSE
)

DEPRECATED: center_feature_batch_means_df

Description

Use center_feature_batch() with ⁠format="long", stat="means"⁠.

Usage

center_feature_batch_means_df(
  df_long,
  sample_annotation = NULL,
  sample_id_col = "FullRunName",
  batch_col = "MS_batch",
  feature_id_col = "peptide_group_label",
  measure_col = "Intensity",
  keep_all = "default",
  no_fit_imputed = TRUE,
  qual_col = NULL,
  qual_value = NULL
)

Arguments

df_long

data frame where each row is a single feature in a single sample. It minimally has a sample_id_col, a feature_id_col and a measure_col, but usually also an m_score (in OpenSWATH output result file). See help("example_proteome") for more details.

sample_annotation

data frame with:

  1. sample_id_col (this can be repeated as row names)

  2. biological covariates

  3. technical covariates (batches etc)

. See help("example_sample_annotation")

sample_id_col

name of the column in sample_annotation table, where the filenames (colnames of the data_matrix are found).

batch_col

column in sample_annotation that should be used for batch comparison (or other, non-batch factor to be mapped to color in plots).

feature_id_col

name of the column with feature/gene/peptide/protein ID used in the long format representation df_long. In the wide formatted representation data_matrix this corresponds to the row names.

measure_col

if df_long is among the parameters, it is the column with expression/abundance/intensity; otherwise, it is used internally for consistency.

keep_all

when transforming the data (normalize, correct) - acceptable values: all/default/minimal (which set of columns be kept).

no_fit_imputed

(logical) whether to use imputed (requant) values, as flagged in qual_col by qual_value for data transformation

qual_col

column to color point by certain value denoted by qual_value. Design with inferred/requant values in OpenSWATH output data, which means argument value has to be set to m_score.

qual_value

value in qual_col to color. For OpenSWATH data, this argument value has to be set to 2 (this is an m_score value for imputed values (requant values).

Value

A data.frame in long format with batch-corrected values in measure_col and original values preserved in preBatchCorr_[measure_col].

Examples

# Use the unified replacement with `format = "long"` and `stat = "means"`.
args(center_feature_batch)

DEPRECATED: center_feature_batch_means_dm

Description

Use center_feature_batch() with ⁠format="wide", stat="means"⁠.

Usage

center_feature_batch_means_dm(
  data_matrix,
  sample_annotation,
  sample_id_col = "FullRunName",
  batch_col = "MS_batch",
  feature_id_col = "peptide_group_label",
  measure_col = "Intensity"
)

Arguments

data_matrix

features (in rows) vs samples (in columns) matrix, with feature IDs in rownames and file/sample names as colnames. See "example_proteome_matrix" for more details (to call the description, use help("example_proteome_matrix"))

sample_annotation

data frame with:

  1. sample_id_col (this can be repeated as row names)

  2. biological covariates

  3. technical covariates (batches etc)

. See help("example_sample_annotation")

sample_id_col

name of the column in sample_annotation table, where the filenames (colnames of the data_matrix are found).

batch_col

column in sample_annotation that should be used for batch comparison (or other, non-batch factor to be mapped to color in plots).

feature_id_col

name of the column with feature/gene/peptide/protein ID used in the long format representation df_long. In the wide formatted representation data_matrix this corresponds to the row names.

measure_col

if df_long is among the parameters, it is the column with expression/abundance/intensity; otherwise, it is used internally for consistency.

Value

A numeric matrix of batch-corrected values (features ×\times samples).

Examples

# Use the unified replacement with `format = "wide"` and `stat = "means"`.
args(center_feature_batch)

DEPRECATED: center_feature_batch_medians_df

Description

Use center_feature_batch() with ⁠format="long", stat="medians"⁠.

Usage

center_feature_batch_medians_df(
  df_long,
  sample_annotation = NULL,
  sample_id_col = "FullRunName",
  batch_col = "MS_batch",
  feature_id_col = "peptide_group_label",
  measure_col = "Intensity",
  keep_all = "default",
  no_fit_imputed = TRUE,
  qual_col = NULL,
  qual_value = NULL
)

Arguments

df_long

data frame where each row is a single feature in a single sample. It minimally has a sample_id_col, a feature_id_col and a measure_col, but usually also an m_score (in OpenSWATH output result file). See help("example_proteome") for more details.

sample_annotation

data frame with:

  1. sample_id_col (this can be repeated as row names)

  2. biological covariates

  3. technical covariates (batches etc)

. See help("example_sample_annotation")

sample_id_col

name of the column in sample_annotation table, where the filenames (colnames of the data_matrix are found).

batch_col

column in sample_annotation that should be used for batch comparison (or other, non-batch factor to be mapped to color in plots).

feature_id_col

name of the column with feature/gene/peptide/protein ID used in the long format representation df_long. In the wide formatted representation data_matrix this corresponds to the row names.

measure_col

if df_long is among the parameters, it is the column with expression/abundance/intensity; otherwise, it is used internally for consistency.

keep_all

when transforming the data (normalize, correct) - acceptable values: all/default/minimal (which set of columns be kept).

no_fit_imputed

(logical) whether to use imputed (requant) values, as flagged in qual_col by qual_value for data transformation

qual_col

column to color point by certain value denoted by qual_value. Design with inferred/requant values in OpenSWATH output data, which means argument value has to be set to m_score.

qual_value

value in qual_col to color. For OpenSWATH data, this argument value has to be set to 2 (this is an m_score value for imputed values (requant values).

Value

A data.frame in long format with batch-corrected values in measure_col and original values preserved in preBatchCorr_[measure_col].

Examples

# Use the unified replacement with `format = "long"` and `stat = "medians"`.
args(center_feature_batch)

DEPRECATED: center_feature_batch_medians_dm

Description

Use center_feature_batch() with ⁠format="wide", stat="medians"⁠.

Usage

center_feature_batch_medians_dm(
  data_matrix,
  sample_annotation,
  sample_id_col = "FullRunName",
  batch_col = "MS_batch",
  feature_id_col = "peptide_group_label",
  measure_col = "Intensity"
)

Arguments

data_matrix

features (in rows) vs samples (in columns) matrix, with feature IDs in rownames and file/sample names as colnames. See "example_proteome_matrix" for more details (to call the description, use help("example_proteome_matrix"))

sample_annotation

data frame with:

  1. sample_id_col (this can be repeated as row names)

  2. biological covariates

  3. technical covariates (batches etc)

. See help("example_sample_annotation")

sample_id_col

name of the column in sample_annotation table, where the filenames (colnames of the data_matrix are found).

batch_col

column in sample_annotation that should be used for batch comparison (or other, non-batch factor to be mapped to color in plots).

feature_id_col

name of the column with feature/gene/peptide/protein ID used in the long format representation df_long. In the wide formatted representation data_matrix this corresponds to the row names.

measure_col

if df_long is among the parameters, it is the column with expression/abundance/intensity; otherwise, it is used internally for consistency.

Value

A numeric matrix of batch-corrected values (features ×\times samples).

Examples

# Use the unified replacement with `format = "wide"` and `stat = "medians"`.
args(center_feature_batch)

Check if sample annotation is consistent with data matrix and join the two

Description

Check if sample annotation is consistent with data matrix and join the two

Usage

check_sample_consistency(
  sample_annotation,
  sample_id_col,
  df_long,
  batch_col = NULL,
  order_col = NULL,
  facet_col = NULL,
  merge = TRUE
)

Arguments

sample_annotation

data frame with:

  1. sample_id_col (this can be repeated as row names)

  2. biological covariates

  3. technical covariates (batches etc)

. See help("example_sample_annotation")

sample_id_col

name of the column in sample_annotation table, where the filenames (colnames of the data_matrix are found).

df_long

data frame where each row is a single feature in a single sample. It minimally has a sample_id_col, a feature_id_col and a measure_col, but usually also an m_score (in OpenSWATH output result file). See help("example_proteome") for more details.

batch_col

column in sample_annotation that should be used for batch comparison (or other, non-batch factor to be mapped to color in plots).

order_col

column in sample_annotation that determines sample order. It is used for in initial assessment plots (plot_sample_mean_or_boxplot) and feature-level diagnostics (feature_level_diagnostics). Can be 'NULL' if sample order is irrelevant (e.g. in genomic experiments). For more details, order definition/inference, see define_sample_order and date_to_sample_order

facet_col

column in sample_annotation with a batch factor to separate plots into facets; usually 2nd to batch_col. Most meaningful for multi-instrument MS experiments (where each instrument has its own order-associated effects (see order_col) or simultaneous examination of two batch factors (e.g. preparation day and measurement day). For single-instrument case should be set to 'NULL'

merge

(logical) whether to merge df_long with sample_annotation or not

Value

'df_long'. When 'sample_annotation' is supplied and 'merge = TRUE', it is inner-joined to 'df_long' by the applicable annotation columns, so only intersecting sample identifiers remain. When 'merge = FALSE' or 'sample_annotation = NULL', 'df_long' is returned without merging.

Examples

# Load necessary datasets
data(
    list = c("example_proteome", "example_sample_annotation"),
    package = "proBatch"
)

df_test <- check_sample_consistency(
    sample_annotation = example_sample_annotation,
    df_long = example_proteome, sample_id_col = "FullRunName",
    batch_col = NULL, order_col = NULL, facet_col = NULL
)

Convert factor and numeric columns

Description

Convert specified factor columns to factor type and numeric columns to numeric.

Usage

convert_annotation_classes(df, factor_columns, numeric_columns)

Arguments

df

data frame with sample annotations.

factor_columns

character vector of factor columns.

numeric_columns

character vector of numeric columns.

Value

data frame with converted columns.

Examples

annotation <- data.frame(
    batch = c("A", "B"),
    injection_order = c("1", "2")
)
converted <- convert_annotation_classes(
    annotation,
    factor_columns = "batch",
    numeric_columns = "injection_order"
)
vapply(converted, class, character(1))

Batch correction methods for normalized data

Description

Batch correction of normalized data to bring each feature within each batch to a comparable scale. The following methods are available:

  1. Per-feature centering by median/mean: center_feature_batch() — unified API for long ("long") and wide ("wide") data via format, and for medians/means via stat. Deprecated wrappers: center_feature_batch_medians_df(), center_feature_batch_means_df(), center_feature_batch_medians_dm(), center_feature_batch_means_dm() now forward to center_feature_batch() and emit deprecation warnings.

  2. Discrete batch correction with ComBat: correct_with_ComBat() adjusts for discrete batch effects using parametric or non-parametric empirical Bayes (Johnson et al., 2007). Missing data: ComBat requires an NA-free matrix. If your data contain missing values, use fill_the_missing = "drop_features" to drop NA-containing features or fill_the_missing = "fill" with an explicit fill_value to impute before calling ComBat.

  3. Linear batch correction with limma: correct_with_removeBatchEffect() removes linear batch effects via limma::removeBatchEffect. Missing data: NA values in the expression/intensity matrix are allowed; the design matrix (batch/covariates) must be free of missing values.

  4. Continuous drift correction: adjust_batch_trend_df() fits and removes within-batch trends (e.g., LOESS) and is typically followed by a discrete adjustment such as center_feature_batch(), correct_with_ComBat(), or correct_with_removeBatchEffect().

Alternatively, use the wrapper correct_batch_effects() to combine continuous and/or discrete corrections in one call.

Adjust batch signal trend with the custom (continuous) fit. Should be followed by discrete corrections, e.g. center_feature_batch() or correct_with_ComBat(). Available for both long format data frame (adjust_batch_trend_df()) and data matrix (adjust_batch_trend_dm()).

Optional continuous drift removal + discrete adjustment via "MedianCentering", "MeanCentering", "ComBat", or "removeBatchEffect". Works for long or wide via format.

Usage

adjust_batch_trend_dm(
  data_matrix,
  sample_annotation,
  batch_col = "MS_batch",
  feature_id_col = "peptide_group_label",
  sample_id_col = "FullRunName",
  measure_col = "Intensity",
  order_col = "order",
  fit_func = "loess_regression",
  return_fit_df = TRUE,
  no_fit_imputed = TRUE,
  qual_col = NULL,
  qual_value = NULL,
  min_measurements = 8,
  ...
)

adjust_batch_trend_df(
  df_long,
  sample_annotation = NULL,
  batch_col = "MS_batch",
  feature_id_col = "peptide_group_label",
  sample_id_col = "FullRunName",
  measure_col = "Intensity",
  order_col = "order",
  keep_all = "default",
  fit_func = "loess_regression",
  no_fit_imputed = TRUE,
  qual_col = NULL,
  qual_value = NULL,
  min_measurements = 8,
  ...
)

correct_batch_effects(
  x,
  sample_annotation,
  format = c("long", "wide"),
  continuous_func = NULL,
  discrete_func = c("MedianCentering", "MeanCentering", "ComBat", "removeBatchEffect"),
  batch_col = "MS_batch",
  feature_id_col = "peptide_group_label",
  sample_id_col = "FullRunName",
  measure_col = "Intensity",
  order_col = "order",
  keep_all = "default",
  no_fit_imputed = TRUE,
  qual_col = NULL,
  qual_value = NULL,
  fill_the_missing = "error",
  par.prior = TRUE,
  covariates_cols = NULL,
  min_measurements = 8,
  ...,
  fill_value = NULL
)

Arguments

data_matrix

features (in rows) vs samples (in columns) matrix, with feature IDs in rownames and file/sample names as colnames. See "example_proteome_matrix" for more details (to call the description, use help("example_proteome_matrix"))

sample_annotation

data frame with:

  1. sample_id_col (this can be repeated as row names)

  2. biological covariates

  3. technical covariates (batches etc)

. See help("example_sample_annotation")

batch_col

column in sample_annotation that should be used for batch comparison (or other, non-batch factor to be mapped to color in plots).

feature_id_col

name of the column with feature/gene/peptide/protein ID used in the long format representation df_long. In the wide formatted representation data_matrix this corresponds to the row names.

sample_id_col

name of the column in sample_annotation table, where the filenames (colnames of the data_matrix are found).

measure_col

if df_long is among the parameters, it is the column with expression/abundance/intensity; otherwise, it is used internally for consistency.

order_col

column in sample_annotation that determines sample order. It is used for in initial assessment plots (plot_sample_mean_or_boxplot) and feature-level diagnostics (feature_level_diagnostics). Can be 'NULL' if sample order is irrelevant (e.g. in genomic experiments). For more details, order definition/inference, see define_sample_order and date_to_sample_order

fit_func

Function used for trend fitting (e.g., "loess_regression").

return_fit_df

Logical; whether adjust_batch_trend_dm() returns the fit_df (for curve inspection) alongside the corrected matrix.

no_fit_imputed

(logical) whether to use imputed (requant) values, as flagged in qual_col by qual_value for data transformation

qual_col

column to color point by certain value denoted by qual_value. Design with inferred/requant values in OpenSWATH output data, which means argument value has to be set to m_score.

qual_value

value in qual_col to color. For OpenSWATH data, this argument value has to be set to 2 (this is an m_score value for imputed values (requant values).

min_measurements

Minimum number of samples per batch required for fitting.

...

Further arguments passed to the continuous fitter when enabled and to limma::removeBatchEffect() when that discrete method is selected. They are not forwarded to centering or ComBat.

df_long

data frame where each row is a single feature in a single sample. It minimally has a sample_id_col, a feature_id_col and a measure_col, but usually also an m_score (in OpenSWATH output result file). See help("example_proteome") for more details.

keep_all

when transforming the data (normalize, correct) - acceptable values: all/default/minimal (which set of columns be kept).

x

Data in long (data.frame) or wide (matrix) form, controlled by format.

format

One of "long" or "wide".

continuous_func

e.g. "loess_regression" or NULL.

discrete_func

batch method name.

fill_the_missing

Missing-value policy applied before discrete correction: "error" (default), "keep", "drop_features", or "fill". With "keep", missing values are passed through; ComBat still requires an NA-free matrix, while removeBatchEffect can model expression values containing NA. For one release, FALSE, a numeric scalar, and "remove", "rm", or "REMOVE" are translated with a deprecation warning. Explicit NULL is an error.

par.prior

Logical; use parametric prior (ComBat) or non-parametric.

covariates_cols

Optional character vector of sample_annotation columns included in mod for ComBat (biological or nuisance covariates).

fill_value

Finite numeric scalar used only with fill_the_missing = "fill".

Value

Returns data in the same format as input (data_matrix or df_long). For long-format discrete correction, original values from measure_col are preserved in "preBatchCorr_[measure_col]"; trend adjustment instead uses "preTrendFit_[measure_col]". Corrected values are written to measure_col.

The function adjust_batch_trend_dm(), if return_fit_df = TRUE, returns a list with:

  1. corrected_dm — corrected data matrix

  2. fit_df — data frame to inspect fitted curves

References

Johnson WE, Li C, Rabinovic A (2007). Adjusting batch effects in microarray expression data using empirical Bayes methods. Biostatistics 8(1):118–127. Smyth GK (2025). limma User's Guide, Bioconductor (see removeBatchEffect / lmFit). Leek JT et al. (2024). sva vignette, Bioconductor.

See Also

center_feature_batch, adjust_batch_trend_df, adjust_batch_trend_dm, correct_with_ComBat, correct_with_removeBatchEffect, correct_batch_effects

fit_nonlinear, plot_with_fitting_curve

Examples

data(
    list = c("example_sample_annotation", "example_proteome"),
    package = "proBatch"
)
test_peptides <- unique(example_proteome$peptide_group_label)[1:3]
test_df <- subset(example_proteome, peptide_group_label %in% test_peptides)

# 1) Per-feature median centering
median_centered_df <- center_feature_batch(
    x = test_df,
    sample_annotation = example_sample_annotation,
    format = "long",
    stat = "medians",
    no_fit_imputed = FALSE
)

# 2) ComBat (discrete) — drop NA features first if needed
combat_corrected_df <- correct_with_ComBat(
    x = test_df,
    sample_annotation = example_sample_annotation,
    format = "long",
    fill_the_missing = "drop_features",
    no_fit_imputed = FALSE
)

# 3) Continuous drift correction (LOESS), then discrete centering if desired
adjusted_df <- adjust_batch_trend_df(
    df_long = test_df,
    sample_annotation = example_sample_annotation,
    span = 0.7, min_measurements = 8,
    no_fit_imputed = FALSE
)
plot_fit <- plot_with_fitting_curve(
    unique(adjusted_df$peptide_group_label),
    df_long = adjusted_df,
    measure_col = "preTrendFit_Intensity",
    fit_df = adjusted_df,
    sample_annotation = example_sample_annotation
)

# 4) One-call wrapper (continuous + discrete)
batch_corrected_df <- correct_batch_effects(
    x = test_df, sample_annotation = example_sample_annotation,
    format = "long",
    continuous_func = "loess_regression",
    discrete_func = "MedianCentering",
    batch_col = "MS_batch",
    fill_the_missing = "keep",
    no_fit_imputed = FALSE,
    span = 0.7, min_measurements = 8
)

DEPRECATED: correct_batch_effects_df

Description

Use correct_batch_effects() with format="long".

Usage

correct_batch_effects_df(
  df_long,
  sample_annotation,
  continuous_func = NULL,
  discrete_func = c("MedianCentering", "MeanCentering", "ComBat", "removeBatchEffect"),
  batch_col = "MS_batch",
  feature_id_col = "peptide_group_label",
  sample_id_col = "FullRunName",
  measure_col = "Intensity",
  order_col = "order",
  keep_all = "default",
  no_fit_imputed = TRUE,
  qual_col = NULL,
  qual_value = NULL,
  fill_the_missing = "error",
  par.prior = TRUE,
  covariates_cols = NULL,
  min_measurements = 8,
  ...,
  fill_value = NULL
)

Arguments

df_long

data frame where each row is a single feature in a single sample. It minimally has a sample_id_col, a feature_id_col and a measure_col, but usually also an m_score (in OpenSWATH output result file). See help("example_proteome") for more details.

sample_annotation

data frame with:

  1. sample_id_col (this can be repeated as row names)

  2. biological covariates

  3. technical covariates (batches etc)

. See help("example_sample_annotation")

continuous_func

e.g. "loess_regression" or NULL.

discrete_func

batch method name.

batch_col

column in sample_annotation that should be used for batch comparison (or other, non-batch factor to be mapped to color in plots).

feature_id_col

name of the column with feature/gene/peptide/protein ID used in the long format representation df_long. In the wide formatted representation data_matrix this corresponds to the row names.

sample_id_col

name of the column in sample_annotation table, where the filenames (colnames of the data_matrix are found).

measure_col

if df_long is among the parameters, it is the column with expression/abundance/intensity; otherwise, it is used internally for consistency.

order_col

column in sample_annotation that determines sample order. It is used for in initial assessment plots (plot_sample_mean_or_boxplot) and feature-level diagnostics (feature_level_diagnostics). Can be 'NULL' if sample order is irrelevant (e.g. in genomic experiments). For more details, order definition/inference, see define_sample_order and date_to_sample_order

keep_all

when transforming the data (normalize, correct) - acceptable values: all/default/minimal (which set of columns be kept).

no_fit_imputed

(logical) whether to use imputed (requant) values, as flagged in qual_col by qual_value for data transformation

qual_col

column to color point by certain value denoted by qual_value. Design with inferred/requant values in OpenSWATH output data, which means argument value has to be set to m_score.

qual_value

value in qual_col to color. For OpenSWATH data, this argument value has to be set to 2 (this is an m_score value for imputed values (requant values).

fill_the_missing

Missing-value policy applied before discrete correction: "error" (default), "keep", "drop_features", or "fill". With "keep", missing values are passed through; ComBat still requires an NA-free matrix, while removeBatchEffect can model expression values containing NA. For one release, FALSE, a numeric scalar, and "remove", "rm", or "REMOVE" are translated with a deprecation warning. Explicit NULL is an error.

par.prior

Logical; use parametric prior (ComBat) or non-parametric.

covariates_cols

Optional character vector of sample_annotation columns included in mod for ComBat (biological or nuisance covariates).

min_measurements

Minimum number of samples per batch required for fitting.

...

Further arguments forwarded to correct_batch_effects().

fill_value

Finite numeric scalar used only with fill_the_missing = "fill".

Value

A data.frame in long format with batch-corrected values in measure_col.

Examples

# Use the unified replacement with `format = "long"`.
args(correct_batch_effects)

DEPRECATED: correct_batch_effects_dm

Description

Use correct_batch_effects() with format="wide".

Usage

correct_batch_effects_dm(
  data_matrix,
  sample_annotation,
  continuous_func = NULL,
  discrete_func = c("MedianCentering", "MeanCentering", "ComBat", "removeBatchEffect"),
  batch_col = "MS_batch",
  feature_id_col = "peptide_group_label",
  sample_id_col = "FullRunName",
  measure_col = "Intensity",
  order_col = "order",
  min_measurements = 8,
  no_fit_imputed = TRUE,
  fill_the_missing = "error",
  par.prior = TRUE,
  covariates_cols = NULL,
  ...,
  fill_value = NULL
)

Arguments

data_matrix

features (in rows) vs samples (in columns) matrix, with feature IDs in rownames and file/sample names as colnames. See "example_proteome_matrix" for more details (to call the description, use help("example_proteome_matrix"))

sample_annotation

data frame with:

  1. sample_id_col (this can be repeated as row names)

  2. biological covariates

  3. technical covariates (batches etc)

. See help("example_sample_annotation")

continuous_func

e.g. "loess_regression" or NULL.

discrete_func

batch method name.

batch_col

column in sample_annotation that should be used for batch comparison (or other, non-batch factor to be mapped to color in plots).

feature_id_col

name of the column with feature/gene/peptide/protein ID used in the long format representation df_long. In the wide formatted representation data_matrix this corresponds to the row names.

sample_id_col

name of the column in sample_annotation table, where the filenames (colnames of the data_matrix are found).

measure_col

if df_long is among the parameters, it is the column with expression/abundance/intensity; otherwise, it is used internally for consistency.

order_col

column in sample_annotation that determines sample order. It is used for in initial assessment plots (plot_sample_mean_or_boxplot) and feature-level diagnostics (feature_level_diagnostics). Can be 'NULL' if sample order is irrelevant (e.g. in genomic experiments). For more details, order definition/inference, see define_sample_order and date_to_sample_order

min_measurements

Minimum number of samples per batch required for fitting.

no_fit_imputed

(logical) whether to use imputed (requant) values, as flagged in qual_col by qual_value for data transformation

fill_the_missing

Missing-value policy applied before discrete correction: "error" (default), "keep", "drop_features", or "fill". With "keep", missing values are passed through; ComBat still requires an NA-free matrix, while removeBatchEffect can model expression values containing NA. For one release, FALSE, a numeric scalar, and "remove", "rm", or "REMOVE" are translated with a deprecation warning. Explicit NULL is an error.

par.prior

Logical; use parametric prior (ComBat) or non-parametric.

covariates_cols

Optional character vector of sample_annotation columns included in mod for ComBat (biological or nuisance covariates).

...

Further arguments forwarded to correct_batch_effects().

fill_value

Finite numeric scalar used only with fill_the_missing = "fill".

Value

A numeric matrix of batch-corrected values (features ×\times samples).

Examples

# Use the unified replacement with `format = "wide"`.
args(correct_batch_effects)

ComBat-based batch correction (unified)

Description

Adjusts for discrete batch effects using ComBat. Works for long-format data frames and wide matrices via format. Optionally accepts covariates through covariates_cols (passed as mod).

Usage

correct_with_ComBat(
  x,
  sample_annotation = NULL,
  feature_id_col = "peptide_group_label",
  measure_col = "Intensity",
  sample_id_col = "FullRunName",
  batch_col = "MS_batch",
  format = c("long", "wide"),
  par.prior = TRUE,
  covariates_cols = NULL,
  fill_the_missing = "error",
  keep_all = "default",
  no_fit_imputed = TRUE,
  qual_col = NULL,
  qual_value = NULL,
  ...,
  fill_value = NULL
)

Arguments

x

Data in long (data.frame) or wide (matrix) form, controlled by format.

sample_annotation

data frame with:

  1. sample_id_col (this can be repeated as row names)

  2. biological covariates

  3. technical covariates (batches etc)

. See help("example_sample_annotation")

feature_id_col

name of the column with feature/gene/peptide/protein ID used in the long format representation df_long. In the wide formatted representation data_matrix this corresponds to the row names.

measure_col

if df_long is among the parameters, it is the column with expression/abundance/intensity; otherwise, it is used internally for consistency.

sample_id_col

name of the column in sample_annotation table, where the filenames (colnames of the data_matrix are found).

batch_col

column in sample_annotation that should be used for batch comparison (or other, non-batch factor to be mapped to color in plots).

format

One of "long" or "wide".

par.prior

Logical; ComBat parametric prior (vs non-parametric).

covariates_cols

Optional character vector of sample_annotation columns included in mod for ComBat (biological or nuisance covariates).

fill_the_missing

Missing-value policy prior to ComBat: "error" (default), "keep", "drop_features", or "fill". ComBat still requires the resulting matrix to be NA-free.

keep_all

For long format, columns to retain (see subset_keep_cols()).

no_fit_imputed

If TRUE and qual_col provided, masked values are excluded when building the matrix (original values still corrected).

qual_col

column to color point by certain value denoted by qual_value. Design with inferred/requant values in OpenSWATH output data, which means argument value has to be set to m_score.

qual_value

value in qual_col to color. For OpenSWATH data, this argument value has to be set to 2 (this is an m_score value for imputed values (requant values).

...

Further arguments passed to sva::ComBat().

fill_value

Finite numeric scalar used only with fill_the_missing = "fill".

Value

Matrix if format="wide", data.frame if format="long".

References

Johnson WE et al. (2007) Biostatistics 8(1):118–127; sva vignette.

Examples

data(
    list = c("example_sample_annotation", "example_proteome"),
    package = "proBatch"
)
feature_ids <- c(
    "10062_NVGVSFYADKPEVTQEQK_3",
    "10063_NVGVSFYADKPEVTQEQKK_3"
)
example_subset <- example_proteome[
    example_proteome$peptide_group_label %in% feature_ids,
]
combat_corrected <- correct_with_ComBat(
    x = example_subset,
    sample_annotation = example_sample_annotation,
    format = "long",
    fill_the_missing = "error"
)

DEPRECATED: correct_with_ComBat_df

Description

Use correct_with_ComBat() with format="long".

Usage

correct_with_ComBat_df(
  df_long,
  sample_annotation = NULL,
  feature_id_col = "peptide_group_label",
  measure_col = "Intensity",
  sample_id_col = "FullRunName",
  batch_col = "MS_batch",
  par.prior = TRUE,
  fill_the_missing = "error",
  no_fit_imputed = TRUE,
  qual_col = NULL,
  qual_value = NULL,
  keep_all = "default",
  covariates_cols = NULL,
  ...,
  fill_value = NULL
)

Arguments

df_long

data frame where each row is a single feature in a single sample. It minimally has a sample_id_col, a feature_id_col and a measure_col, but usually also an m_score (in OpenSWATH output result file). See help("example_proteome") for more details.

sample_annotation

data frame with:

  1. sample_id_col (this can be repeated as row names)

  2. biological covariates

  3. technical covariates (batches etc)

. See help("example_sample_annotation")

feature_id_col

name of the column with feature/gene/peptide/protein ID used in the long format representation df_long. In the wide formatted representation data_matrix this corresponds to the row names.

measure_col

if df_long is among the parameters, it is the column with expression/abundance/intensity; otherwise, it is used internally for consistency.

sample_id_col

name of the column in sample_annotation table, where the filenames (colnames of the data_matrix are found).

batch_col

column in sample_annotation that should be used for batch comparison (or other, non-batch factor to be mapped to color in plots).

par.prior

Logical; use parametric prior (ComBat) or non-parametric.

fill_the_missing

Missing-value policy applied before discrete correction: "error" (default), "keep", "drop_features", or "fill". With "keep", missing values are passed through; ComBat still requires an NA-free matrix, while removeBatchEffect can model expression values containing NA. For one release, FALSE, a numeric scalar, and "remove", "rm", or "REMOVE" are translated with a deprecation warning. Explicit NULL is an error.

no_fit_imputed

(logical) whether to use imputed (requant) values, as flagged in qual_col by qual_value for data transformation

qual_col

column to color point by certain value denoted by qual_value. Design with inferred/requant values in OpenSWATH output data, which means argument value has to be set to m_score.

qual_value

value in qual_col to color. For OpenSWATH data, this argument value has to be set to 2 (this is an m_score value for imputed values (requant values).

keep_all

when transforming the data (normalize, correct) - acceptable values: all/default/minimal (which set of columns be kept).

covariates_cols

Optional character vector of sample_annotation columns included in mod for ComBat (biological or nuisance covariates).

...

Further arguments passed to sva::ComBat().

fill_value

Finite numeric scalar used only with fill_the_missing = "fill".

Value

A data.frame in long format with ComBat-corrected values in measure_col and original values preserved in preBatchCorr_[measure_col].

Examples

# Use the unified replacement with `format = "long"`.
args(correct_with_ComBat)

DEPRECATED: correct_with_ComBat_dm

Description

Use correct_with_ComBat() with format="wide".

Usage

correct_with_ComBat_dm(
  data_matrix,
  sample_annotation = NULL,
  feature_id_col = "peptide_group_label",
  measure_col = "Intensity",
  sample_id_col = "FullRunName",
  batch_col = "MS_batch",
  par.prior = TRUE,
  fill_the_missing = "error",
  covariates_cols = NULL,
  ...,
  fill_value = NULL
)

Arguments

data_matrix

features (in rows) vs samples (in columns) matrix, with feature IDs in rownames and file/sample names as colnames. See "example_proteome_matrix" for more details (to call the description, use help("example_proteome_matrix"))

sample_annotation

data frame with:

  1. sample_id_col (this can be repeated as row names)

  2. biological covariates

  3. technical covariates (batches etc)

. See help("example_sample_annotation")

feature_id_col

name of the column with feature/gene/peptide/protein ID used in the long format representation df_long. In the wide formatted representation data_matrix this corresponds to the row names.

measure_col

if df_long is among the parameters, it is the column with expression/abundance/intensity; otherwise, it is used internally for consistency.

sample_id_col

name of the column in sample_annotation table, where the filenames (colnames of the data_matrix are found).

batch_col

column in sample_annotation that should be used for batch comparison (or other, non-batch factor to be mapped to color in plots).

par.prior

Logical; use parametric prior (ComBat) or non-parametric.

fill_the_missing

Missing-value policy applied before discrete correction: "error" (default), "keep", "drop_features", or "fill". With "keep", missing values are passed through; ComBat still requires an NA-free matrix, while removeBatchEffect can model expression values containing NA. For one release, FALSE, a numeric scalar, and "remove", "rm", or "REMOVE" are translated with a deprecation warning. Explicit NULL is an error.

covariates_cols

Optional character vector of sample_annotation columns included in mod for ComBat (biological or nuisance covariates).

...

Further arguments passed to sva::ComBat().

fill_value

Finite numeric scalar used only with fill_the_missing = "fill".

Value

A numeric matrix of ComBat-corrected values (features ×\times samples).

Examples

# Use the unified replacement with `format = "wide"`.
args(correct_with_ComBat)

Batch effect correction with limma::removeBatchEffect (unified)

Description

Removes batch-associated linear effects with removeBatchEffect from limma. Works for long or wide via format. Use covariates_cols to keep biological effects in the design (not removed).

Usage

correct_with_removeBatchEffect(
  x,
  sample_annotation,
  feature_id_col = "peptide_group_label",
  measure_col = "Intensity",
  sample_id_col = "FullRunName",
  batch_col = "MS_batch",
  format = c("long", "wide"),
  covariates_cols = NULL,
  fill_the_missing = "error",
  keep_all = "default",
  ...,
  fill_value = NULL
)

Arguments

x

Data in long (data.frame) or wide (matrix) form, controlled by format.

sample_annotation

data frame with:

  1. sample_id_col (this can be repeated as row names)

  2. biological covariates

  3. technical covariates (batches etc)

. See help("example_sample_annotation")

feature_id_col

name of the column with feature/gene/peptide/protein ID used in the long format representation df_long. In the wide formatted representation data_matrix this corresponds to the row names.

measure_col

if df_long is among the parameters, it is the column with expression/abundance/intensity; otherwise, it is used internally for consistency.

sample_id_col

name of the column in sample_annotation table, where the filenames (colnames of the data_matrix are found).

batch_col

column in sample_annotation that should be used for batch comparison (or other, non-batch factor to be mapped to color in plots).

format

One of "long" or "wide".

covariates_cols

Optional sample_annotation columns for the design matrix (biological or nuisance covariates).

fill_the_missing

Missing-value policy applied before modeling: "error" (default), "keep", "drop_features", or "fill". With "keep", NA values are passed unchanged to limma::removeBatchEffect(). The design matrix (batch_col and covariates_cols) must be NA-free for every policy.

keep_all

For long format, columns to retain (see subset_keep_cols()).

...

Further arguments passed to limma::removeBatchEffect().

fill_value

Finite numeric scalar used only with fill_the_missing = "fill".

Value

Matrix if format="wide", data.frame if format="long" with batch effects removed

See Also

removeBatchEffect

Examples

data(
    list = c("example_sample_annotation", "example_proteome_matrix"),
    package = "proBatch"
)
batch_corrected_matrix <- correct_with_removeBatchEffect(
    example_proteome_matrix,
    example_sample_annotation,
    format = "wide",
    batch_col = "MS_batch",
    covariates_cols = c("Diet", "Sex"),
    fill_the_missing = "drop_features"
)

DEPRECATED: correct_with_removeBatchEffect_df

Description

Use correct_with_removeBatchEffect() with format="long".

Usage

correct_with_removeBatchEffect_df(
  df_long,
  sample_annotation = NULL,
  feature_id_col = "peptide_group_label",
  measure_col = "Intensity",
  sample_id_col = "FullRunName",
  batch_col = "MS_batch",
  covariates_cols = NULL,
  fill_the_missing = "error",
  keep_all = "default",
  ...,
  fill_value = NULL
)

Arguments

df_long

data frame where each row is a single feature in a single sample. It minimally has a sample_id_col, a feature_id_col and a measure_col, but usually also an m_score (in OpenSWATH output result file). See help("example_proteome") for more details.

sample_annotation

data frame with:

  1. sample_id_col (this can be repeated as row names)

  2. biological covariates

  3. technical covariates (batches etc)

. See help("example_sample_annotation")

feature_id_col

name of the column with feature/gene/peptide/protein ID used in the long format representation df_long. In the wide formatted representation data_matrix this corresponds to the row names.

measure_col

if df_long is among the parameters, it is the column with expression/abundance/intensity; otherwise, it is used internally for consistency.

sample_id_col

name of the column in sample_annotation table, where the filenames (colnames of the data_matrix are found).

batch_col

column in sample_annotation that should be used for batch comparison (or other, non-batch factor to be mapped to color in plots).

covariates_cols

Optional character vector of sample_annotation columns included in mod for ComBat (biological or nuisance covariates).

fill_the_missing

Missing-value policy applied before discrete correction: "error" (default), "keep", "drop_features", or "fill". With "keep", missing values are passed through; ComBat still requires an NA-free matrix, while removeBatchEffect can model expression values containing NA. For one release, FALSE, a numeric scalar, and "remove", "rm", or "REMOVE" are translated with a deprecation warning. Explicit NULL is an error.

keep_all

when transforming the data (normalize, correct) - acceptable values: all/default/minimal (which set of columns be kept).

...

Further arguments passed to limma::removeBatchEffect().

fill_value

Finite numeric scalar used only with fill_the_missing = "fill".

Value

A data.frame in long format with batch effects removed in measure_col.

Examples

# Use the unified replacement with `format = "long"`.
args(correct_with_removeBatchEffect)

DEPRECATED: correct_with_removeBatchEffect_dm

Description

Use correct_with_removeBatchEffect() with format="wide".

Usage

correct_with_removeBatchEffect_dm(
  data_matrix,
  sample_annotation,
  feature_id_col = "peptide_group_label",
  measure_col = "Intensity",
  sample_id_col = "FullRunName",
  batch_col = "MS_batch",
  covariates_cols = NULL,
  fill_the_missing = "error",
  ...,
  fill_value = NULL
)

Arguments

data_matrix

features (in rows) vs samples (in columns) matrix, with feature IDs in rownames and file/sample names as colnames. See "example_proteome_matrix" for more details (to call the description, use help("example_proteome_matrix"))

sample_annotation

data frame with:

  1. sample_id_col (this can be repeated as row names)

  2. biological covariates

  3. technical covariates (batches etc)

. See help("example_sample_annotation")

feature_id_col

name of the column with feature/gene/peptide/protein ID used in the long format representation df_long. In the wide formatted representation data_matrix this corresponds to the row names.

measure_col

if df_long is among the parameters, it is the column with expression/abundance/intensity; otherwise, it is used internally for consistency.

sample_id_col

name of the column in sample_annotation table, where the filenames (colnames of the data_matrix are found).

batch_col

column in sample_annotation that should be used for batch comparison (or other, non-batch factor to be mapped to color in plots).

covariates_cols

Optional character vector of sample_annotation columns included in mod for ComBat (biological or nuisance covariates).

fill_the_missing

Missing-value policy applied before discrete correction: "error" (default), "keep", "drop_features", or "fill". With "keep", missing values are passed through; ComBat still requires an NA-free matrix, while removeBatchEffect can model expression values containing NA. For one release, FALSE, a numeric scalar, and "remove", "rm", or "REMOVE" are translated with a deprecation warning. Explicit NULL is an error.

...

Further arguments passed to limma::removeBatchEffect().

fill_value

Finite numeric scalar used only with fill_the_missing = "fill".

Value

A numeric matrix with batch effects removed (features ×\times samples).

See Also

removeBatchEffect

Examples

data(
    list = c("example_sample_annotation", "example_proteome_matrix"),
    package = "proBatch"
)
example_proteome_small <- example_proteome_matrix[1:100, ]
batch_corrected_matrix <- correct_with_removeBatchEffect(
    example_proteome_small,
    example_sample_annotation,
    format = "wide",
    batch_col = "MS_batch",
    covariates_cols = c("Diet", "Sex"),
    fill_the_missing = "drop_features"
)

Prepare peptide annotation from long format data frame

Description

Create light-weight peptide annotation data frame for selection of illustrative proteins

Usage

create_peptide_annotation(
  df_long,
  feature_id_col = "peptide_group_label",
  protein_col = c("ProteinName", "Gene")
)

Arguments

df_long

data frame where each row is a single feature in a single sample. It minimally has a sample_id_col, a feature_id_col and a measure_col, but usually also an m_score (in OpenSWATH output result file). See help("example_proteome") for more details.

feature_id_col

name of the column with feature/gene/peptide/protein ID used in the long format representation df_long. In the wide formatted representation data_matrix this corresponds to the row names.

protein_col

column where protein names are specified

Value

data frame containing peptide annotations

See Also

plot_peptides_of_one_protein, plot_protein_corrplot

Examples

data("example_proteome", package = "proBatch")
generated_peptide_annotation <- create_peptide_annotation(
    example_proteome,
    feature_id_col = "peptide_group_label",
    protein_col = c("Protein")
)

Convert date/time to POSIXct and rank samples by it

Description

Converts date/time columns for sample_annotation to POSIXct format and calculates sample run rank in order column

Usage

date_to_sample_order(
  sample_annotation,
  time_column = c("RunDate", "RunTime"),
  new_time_column = "DateTime",
  dateTimeFormat = c("%b_%d", "%H:%M:%S"),
  new_order_col = "order",
  instrument_col = "instrument"
)

Arguments

sample_annotation

data frame with:

  1. sample_id_col (this can be repeated as row names)

  2. biological covariates

  3. technical covariates (batches etc)

. See help("example_sample_annotation")

time_column

name of the column(s) where run date & time are specified. These will be used to determine the run order

new_time_column

name of the new column that will contain the converted date/time value

dateTimeFormat

POSIX format of the date and time. See as.POSIXct from base R for details

new_order_col

name of the column containing the generated sample run order based on time columns

instrument_col

name of the column denoting the instrument used for measurements

Value

sample annotation file with a new column new_time_column with POSIX-formatted date & new_order_col used in some diagnostic plots (e.g. plot_iRT, plot_sample_mean)

Examples

data("example_sample_annotation", package = "proBatch")
sample_annotation_wOrder <- date_to_sample_order(
    example_sample_annotation,
    time_column = c("RunDate", "RunTime"),
    new_time_column = "new_DateTime",
    dateTimeFormat = c("%b_%d", "%H:%M:%S"),
    new_order_col = "new_order",
    instrument_col = NULL
)

Convert date/time to POSIXct

Description

convert date/time column of sample_annotation to POSIX format required to keep number-like behavior

Usage

dates_to_posix(
  sample_annotation,
  time_column = c("RunDate", "RunTime"),
  new_time_column = "DateTime",
  dateTimeFormat = c("%b_%d", "%H:%M:%S"),
  tz = "GMT",
  locale = "en_US.UTF-8"
)

Arguments

sample_annotation

data frame with:

  1. sample_id_col (this can be repeated as row names)

  2. biological covariates

  3. technical covariates (batches etc)

. See help("example_sample_annotation")

time_column

name of the column(s) where run date & time are specified. These will be used to determine the run order

new_time_column

name of the new column that will contain the converted date/time value

dateTimeFormat

POSIX format of the date and time. See as.POSIXct from base R for details

tz

for time zone, 'GMT' by default

locale

for locale, 'en_US.UTF-8' by default

Value

sample annotation file with a new column new_time_column with POSIX-formatted date

Examples

data("example_sample_annotation", package = "proBatch")
date_to_posix <- dates_to_posix(example_sample_annotation,
    time_column = c("RunDate", "RunTime"),
    new_time_column = "DateTime_new",
    dateTimeFormat = c("%b_%d", "%H:%M:%S")
)

Defining sample order internally

Description

Defining sample order internally

Usage

define_sample_order(
  order_col,
  sample_annotation,
  facet_col,
  batch_col,
  df_long,
  sample_id_col,
  color_by_batch
)

Arguments

order_col

column in sample_annotation that determines sample order. It is used for in initial assessment plots (plot_sample_mean_or_boxplot) and feature-level diagnostics (feature_level_diagnostics). Can be 'NULL' if sample order is irrelevant (e.g. in genomic experiments). For more details, order definition/inference, see define_sample_order and date_to_sample_order

sample_annotation

data frame with:

  1. sample_id_col (this can be repeated as row names)

  2. biological covariates

  3. technical covariates (batches etc)

. See help("example_sample_annotation")

facet_col

column in sample_annotation with a batch factor to separate plots into facets; usually 2nd to batch_col. Most meaningful for multi-instrument MS experiments (where each instrument has its own order-associated effects (see order_col) or simultaneous examination of two batch factors (e.g. preparation day and measurement day). For single-instrument case should be set to 'NULL'

batch_col

column in sample_annotation that should be used for batch comparison (or other, non-batch factor to be mapped to color in plots).

df_long

data frame where each row is a single feature in a single sample. It minimally has a sample_id_col, a feature_id_col and a measure_col, but usually also an m_score (in OpenSWATH output result file). See help("example_proteome") for more details.

sample_id_col

name of the column in sample_annotation table, where the filenames (colnames of the data_matrix are found).

color_by_batch

(logical) whether to color points and connecting lines by batch factor as defined by batch_col.

Value

list of two items: order_col new name and new df_long

See Also

plot_sample_mean_or_boxplot, feature_level_diagnostics

Examples

data(
    list = c("example_proteome", "example_sample_annotation"),
    package = "proBatch"
)
sample_order <- define_sample_order(
    order_col = "order",
    sample_annotation = example_sample_annotation,
    facet_col = NULL, batch_col = "MS_batch", df_long = example_proteome,
    sample_id_col = "FullRunName", color_by_batch = TRUE
)
new_order_col <- sample_order$order_col
df_long <- sample_order$df_long

Detect nested batch variables

Description

Detect nested batch variables

Usage

detect_nested_batches(sample_annotation, batch_cols)

Arguments

sample_annotation

data frame with sample annotations.

batch_cols

character vector with two or more batch variables.

Value

A list with adjacency matrix of nesting relations (parent -> child), edge list, equivalent (bijective) partitions, topological ordering (if acyclic), and suggestions. The object has class "pb_nested_batches".

Examples

data("example_ecoli_data", package = "proBatch")
meta <- example_ecoli_data$all_metadata
detect_nested_batches(meta, batch_cols = c("Lab", "Condition"))

Detect outlier samples in PCA space

Description

Detect outlier samples in PCA space

Usage

detect_outlier_samples(
  data_matrix,
  sample_annotation = NULL,
  batch_col = NULL,
  n_pcs = 10,
  center = TRUE,
  scale. = TRUE,
  robust = TRUE,
  cutoff = 0.99,
  pbf_name = NULL
)

Arguments

data_matrix

features (in rows) vs samples (in columns) matrix, with feature IDs in rownames and file/sample names as colnames. See "example_proteome_matrix" for more details (to call the description, use help("example_proteome_matrix"))

sample_annotation

optional sample annotation data frame.

batch_col

optional batch column to report per-batch summaries.

n_pcs

number of principal components to use.

center

logical; center variables before PCA.

scale.

logical; scale variables before PCA.

robust

logical; use robust covariance via MASS::cov.rob. If robust estimation flags multiple batches as complete outliers, the function falls back to classical covariance.

cutoff

probability for the chi-square cutoff used to flag outliers.

pbf_name

Assay name used when 'data_matrix' is a 'ProBatchFeatures' object. If 'NULL', [pb_current_assay()] is used.

Value

A data frame with sample_id, batch (if provided), mdist, and is_outlier. Attributes include cutoff, df, mdist_cutoff, and outlier_mode. The object has class "pb_outliers". When batch_col is supplied, the batch_summary attribute contains per-batch outlier counts and percentages.

Examples

data("example_ecoli_data", package = "proBatch")
meta <- example_ecoli_data$all_metadata
dm <- as.matrix(example_ecoli_data$all_protein_groups)[1:100, ]
outliers <- detect_outlier_samples(
    dm,
    sample_annotation = meta,
    batch_col = "Lab",
    n_pcs = 5
)

Example multi-center DIA LFQ E. coli proteomics (DIA-NN)

Description

An example dataset illustrating a typical multi-center DIA (data-independent acquisition) proteomics study processed with DIA-NN. Subset of 400 protein groups and 1463 precursors from the PRIDE ID PXD053812. Study design summary: - Five independent centers. - Per center: 23 or 24 samples of E. coli grown in different media (Pyruvate vs Glucose) The distributed object is a named list that contains the combined study-level tables derived from all centers (per-center sub-lists were removed to keep the package size below 5 MB).

Format

A named list with four elements:

'all_metadata'

'data.frame' (118 rows × 3 columns) with per-sample annotation. Columns: 'Run', 'Lab', and 'Condition'.

'all_precursors'

'data.frame' (1463 rows × 118 columns) containing the combined precursor-level Precursor.Normalised intensities (rows = precursors, columns = samples).

'all_protein_groups'

'data.frame' (400 rows × 118 columns) containing the combined protein group-level PG.MaxLFQ intensities.

'all_precursor_pg_match'

'data.frame' (1463 rows × 2 columns) linking 'Precursor.Id' to 'Protein.Ids'.

Value

A named list containing the combined metadata, quantification matrices, and precursor-to-protein mapping.

Source

PRIDE ID PXD053812

Examples

data("example_ecoli_data", package = "proBatch")
names(example_ecoli_data)

Peptide annotation data

Description

This is data from Aging study annotated with gene names

Format

A data frame with 366 rows and 3 variables:

peptide_group_label

peptide group label ID, identical to peptide_group_label in example_proteome

Gene

HUGO gene ID

ProteinName

protein group name as specified in example_proteome

Value

A data frame with 366 rows and 3 variables.

Examples

data("example_peptide_annotation", package = "proBatch")
head(example_peptide_annotation)

Example protein data in long format

Description

This is OpenSWATH-output data from Aging study with all iRT, spike-in peptides, few representative peptides and proteins for signal improvement demonstration. Using long_to_matrix can be converted to example_proteome_matrix

Format

A data frame with 85278 rows and 5 variables:

peptide_group_label

peptide ID, which is regular feature level. This column is mostly used as feature_id_col

used for merging with "example_peptide_annotation"

Intensity

peptide group intensity in given sample. Used in function as measure_col

Protein

Protein group ID, specified as N/UniProtID1|UniProtID2|..., where N is number of protein peptide group maps to. If 1/UniProtID, then this is proteotypic peptide, in functions used as protein_col

FullRunName

name of the file, in most functions used for sample_id_col

m_score

logical column marking peptide-identification quality, usable as qual_col

...

Value

A data frame with 85278 rows and 5 variables.

Source

PRIDE ID will be added upon the publication of the dataset

Examples

data("example_proteome", package = "proBatch")
head(example_proteome)

Example protein data in matrix

Description

This is measurement data from Aging study with columns representing samples and rows representing peptides. Generated by long_to_matrix

Format

A matrix with 366 rows and 233 columns:

Value

A matrix with 366 rows and 233 columns.

Source

PRIDE ID will be added upon the publication of the dataset

Examples

data("example_proteome_matrix", package = "proBatch")
dim(example_proteome_matrix)

Sample annotation data version 1

Description

This is data from BXD mouse population aging study with mock instruments to show how instrument-specific functionality works

Format

A data frame with 233 rows and 11 variables:

FullRunName

name of the file with the measurement for each sample, referred to as sample_id_col

MS_batch

mass-spectrometry batch: character vector with four manually annotated batch labels

EarTag

mouse ID, i.e. ID of the biological object. Only 14 mice have been replicated, one mouse was profiled 7 times.

Strain

mouse strain ID from BXD population set - biological covariate #1, 51 Strain represented

Diet

diet, biological covariate #2 - either HF = 'High Fat Diet' or CD = 'Chow Diet'

Sex

mice sex - biological covariate #3

RunDate

mass-spectrometry running date. In combination with RunTime used for running order determination. Character vector

RunTime

mass-spectrometry running time. In combination with RunDate used for running order determination. Character vector

DateTime

date and time of class "POSIXct"/"POSIXt" generated by date_to_sample_order

order

order of samples generated by sorting DateTime in date_to_sample_order

digestion_batch

numeric peptide digestion batch with four manually annotated values

...

Value

A data frame with 233 rows and 11 variables.

Examples

data("example_sample_annotation", package = "proBatch")
head(example_sample_annotation)

Plotting peptide measurements

Description

Creates a peptide faceted ggplot2 plot of the value in measure_col vs order_col (if 'NULL', x-axis is simply a sample name order). Additionally, the resulting plot can also be colored either by batch factor, by quality factor (e.g. imputed/non-imputed) and, if needed, faceted by another batch factor, e.g. an instrument. If the non-linear curve was fit, this can also be added to the plot, see functions specific to each case below

Usage

plot_single_feature(
  feature_name,
  df_long,
  sample_annotation = NULL,
  pbf_name = NULL,
  sample_id_col = "FullRunName",
  measure_col = "Intensity",
  feature_id_col = "peptide_group_label",
  geom = c("point", "line"),
  qual_col = NULL,
  qual_value = NULL,
  batch_col = "MS_batch",
  color_by_batch = FALSE,
  color_scheme = "brewer",
  order_col = "order",
  vline_color = "red",
  facet_col = NULL,
  filename = NULL,
  width = NA,
  height = NA,
  units = c("cm", "in", "mm"),
  plot_title = NULL,
  theme = "classic",
  ylimits = NULL,
  base_size = 20
)

plot_peptides_of_one_protein(
  protein_name,
  peptide_annotation = NULL,
  protein_col = "ProteinName",
  df_long,
  sample_annotation = NULL,
  pbf_name = NULL,
  sample_id_col = "FullRunName",
  measure_col = "Intensity",
  feature_id_col = "peptide_group_label",
  geom = c("point", "line"),
  qual_col = NULL,
  qual_value = NULL,
  batch_col = "MS_batch",
  color_by_batch = FALSE,
  color_scheme = "brewer",
  order_col = "order",
  vline_color = "red",
  facet_col = NULL,
  filename = NULL,
  width = NA,
  height = NA,
  units = c("cm", "in", "mm"),
  plot_title = sprintf("Peptides of %s protein", protein_name),
  theme = "classic",
  base_size = 20
)

plot_spike_in(
  spike_ins = "BOVIN",
  peptide_annotation = NULL,
  protein_col = "ProteinName",
  df_long,
  sample_annotation = NULL,
  sample_id_col = "FullRunName",
  measure_col = "Intensity",
  feature_id_col = "peptide_group_label",
  geom = c("point", "line"),
  qual_col = NULL,
  qual_value = NULL,
  batch_col = "MS_batch",
  color_by_batch = FALSE,
  color_scheme = "brewer",
  order_col = "order",
  vline_color = "red",
  facet_col = NULL,
  filename = NULL,
  width = NA,
  height = NA,
  units = c("cm", "in", "mm"),
  plot_title = sprintf("Spike-in %s plots", spike_ins),
  theme = "classic",
  base_size = 20
)

plot_iRT(
  irt_pattern = "iRT",
  peptide_annotation = NULL,
  protein_col = "ProteinName",
  df_long,
  sample_annotation = NULL,
  sample_id_col = "FullRunName",
  measure_col = "Intensity",
  feature_id_col = "peptide_group_label",
  geom = c("point", "line"),
  qual_col = NULL,
  qual_value = NULL,
  batch_col = "MS_batch",
  color_by_batch = FALSE,
  color_scheme = "brewer",
  order_col = "order",
  vline_color = "red",
  facet_col = NULL,
  filename = NULL,
  width = NA,
  height = NA,
  units = c("cm", "in", "mm"),
  plot_title = "iRT peptide profile",
  theme = "classic",
  base_size = 20
)

plot_with_fitting_curve(
  feature_name,
  fit_df,
  fit_value_col = "fit",
  df_long,
  sample_annotation = NULL,
  sample_id_col = "FullRunName",
  measure_col = "Intensity",
  feature_id_col = "peptide_group_label",
  geom = c("point", "line"),
  qual_col = NULL,
  qual_value = NULL,
  batch_col = "MS_batch",
  color_by_batch = FALSE,
  color_scheme = "brewer",
  order_col = "order",
  vline_color = "grey",
  facet_col = NULL,
  filename = NULL,
  width = NA,
  height = NA,
  units = c("cm", "in", "mm"),
  plot_title = sprintf("Fitting curve of %s peptide", paste(feature_name, collapse =
    " ")),
  theme = "classic",
  base_size = 20
)

Arguments

feature_name

name of the selected feature (e.g. peptide) for diagnostic profiling

df_long

data frame where each row is a single feature in a single sample, or a 'ProBatchFeatures' object.

sample_annotation

data frame with:

  1. sample_id_col (this can be repeated as row names)

  2. biological covariates

  3. technical covariates (batches etc)

. See help("example_sample_annotation")

pbf_name

Assay name used when 'df_long' is a 'ProBatchFeatures' object (used by 'plot_single_feature()' and 'plot_peptides_of_one_protein()'). If 'NULL', [pb_current_assay()] is used.

sample_id_col

name of the column in sample_annotation table, where the filenames (colnames of the data_matrix are found).

measure_col

if df_long is among the parameters, it is the column with expression/abundance/intensity; otherwise, it is used internally for consistency.

feature_id_col

name of the column with feature/gene/peptide/protein ID used in the long format representation df_long. In the wide formatted representation data_matrix this corresponds to the row names.

geom

whether to show the feature as points and/or connect by lines (accepted values are: 1. point, line and c('point', 'line'))

qual_col

column to color point by certain value denoted by qual_value. Design with inferred/requant values in OpenSWATH output data, which means argument value has to be set to m_score.

qual_value

value in qual_col to color. For OpenSWATH data, this argument value has to be set to 2 (this is an m_score value for imputed values (requant values).

batch_col

column in sample_annotation that should be used for batch comparison (or other, non-batch factor to be mapped to color in plots).

color_by_batch

(logical) whether to color points and connecting lines by batch factor as defined by batch_col.

color_scheme

a named vector of colors to map to batch_col, names corresponding to the levels of the factor. For continuous variables, vector doesn't need to be named.

order_col

column in sample_annotation that determines sample order. It is used for in initial assessment plots (plot_sample_mean_or_boxplot) and feature-level diagnostics (feature_level_diagnostics). Can be 'NULL' if sample order is irrelevant (e.g. in genomic experiments). For more details, order definition/inference, see define_sample_order and date_to_sample_order

vline_color

color of vertical lines, typically separating different MS batches in ordered runs; should be 'NULL' for experiments without intrinsic order

facet_col

column in sample_annotation with a batch factor to separate plots into facets; usually 2nd to batch_col. Most meaningful for multi-instrument MS experiments (where each instrument has its own order-associated effects (see order_col) or simultaneous examination of two batch factors (e.g. preparation day and measurement day). For single-instrument case should be set to 'NULL'

filename

path where the results are saved. If null the object is returned to the active window; otherwise, the object is save into the file. Currently only pdf and png format is supported

width

option determining the output image width

height

option determining the output image height

units

units: 'cm', 'in' or 'mm'

plot_title

title of the plot (e.g., processing step + representation level (fragments, transitions, proteins) + purpose (meanplot/corrplot etc))

theme

ggplot theme, by default classic. Can be easily overridden

ylimits

range of y-axis to plot feature-level trends

base_size

base font size

protein_name

name of the protein as defined in protein_col

peptide_annotation

long format data frame with peptide ID and their corresponding protein and/or gene annotations. See help("example_peptide_annotation").

protein_col

column where protein names are specified

spike_ins

name of feature(s), typically proteins that were spiked in for control

irt_pattern

substring used to identify iRT proteins in protein_col

fit_df

data frame output of adjust_batch_trend_df to be plotted with the line

fit_value_col

column in fit_df where the values for fitting trend are found

Value

ggplot2 type plot of measure_col vs order_col, faceted by feature_name and (optionally) by facet_col

Examples

data(list = c(
    "example_sample_annotation", "example_proteome",
    "example_peptide_annotation"
), package = "proBatch")

sample_annotation <- example_sample_annotation

feature_ids <- c(
    "10231_QDVDVWLWQQEGSSK_2", "10768_RLESELDGLR_2",
    "10062_NVGVSFYADKPEVTQEQK_3", "10063_NVGVSFYADKPEVTQEQKK_3",
    "1146_ADVTPADFSEWSK_3", "12476_TPVISGGPYEYR_2"
)
peptide_annotation <- subset(
    example_peptide_annotation, peptide_group_label %in% feature_ids)
proteome <- subset(
    example_proteome, peptide_group_label %in% feature_ids)
feature_id <- feature_ids[1]

feature_plot <- plot_single_feature(
    feature_name = feature_id,
    df_long = proteome,
    sample_annotation = sample_annotation,
    color_by_batch = TRUE,
    batch_col = "MS_batch"
)

protein_plot <- plot_peptides_of_one_protein(
    protein_name = "Haao",
    peptide_annotation = peptide_annotation,
    df_long = proteome,
    sample_annotation = sample_annotation,
    protein_col = "Gene"
)

spike_in_plot <- plot_spike_in(
    spike_ins = "BOVINE_A1ag",
    peptide_annotation = peptide_annotation,
    df_long = proteome,
    sample_annotation = sample_annotation,
    protein_col = "Gene"
)

irt_plot <- plot_iRT(
    irt_pattern = "iRT",
    peptide_annotation = peptide_annotation,
    df_long = proteome,
    sample_annotation = sample_annotation,
    protein_col = "Gene"
)

fit_input <- adjust_batch_trend_df(
    proteome[proteome$peptide_group_label == feature_id, ],
    sample_annotation,
    span = 0.7
)

curve_plot <- plot_with_fitting_curve(
    feature_name = feature_id,
    df_long = proteome,
    sample_annotation = sample_annotation,
    fit_df = fit_input
)

Filter metadata columns based on duplication and completeness

Description

Automate common metadata cleaning steps by dropping duplicated columns while retaining the preferred representative and optionally removing columns with excessive missingness. Works on plain data frames as well as ['ProBatchFeatures'] objects.

Usage

filter_metadata_columns(x, ...)

## Default S3 method:
filter_metadata_columns(
  x,
  duplicate_keep = c("first", "last", "pattern"),
  duplicate_pattern = NULL,
  pattern_ignore_case = TRUE,
  pattern_fixed = FALSE,
  min_non_na = NULL,
  max_pct_na = NULL,
  sort = FALSE,
  ...
)

## S3 method for class 'ProBatchFeatures'
filter_metadata_columns(
  x,
  component = c("colData", "rowData"),
  assay = NULL,
  df = NULL,
  inplace = FALSE,
  ...
)

Arguments

x

A data frame or 'ProBatchFeatures' object.

...

Additional arguments passed to specific methods.

duplicate_keep

Strategy for selecting which column to retain within each duplicated set. Choose between keeping the '"first"', '"last"', or the first column whose name matches 'duplicate_pattern' ('"pattern"').

duplicate_pattern

Character pattern used when 'duplicate_keep = "pattern"'. A regular expression is expected unless 'pattern_fixed = TRUE'.

pattern_ignore_case

Logical flag passed to [base::grepl()] when matching 'duplicate_pattern'. Defaults to 'TRUE' as metadata column names are often case-insensitive.

pattern_fixed

Forwarded to the 'fixed' argument of [base::grepl()]. Defaults to 'FALSE' to allow regular expressions.

min_non_na

Optional minimum number of non-missing values a column must contain to be retained. Set to 'NULL' to skip this filter.

max_pct_na

Optional percentage threshold (0–100). Columns with missingness greater than or equal to this value are removed. Set to 'NULL' to disable.

sort

Logical flag forwarded to [metadata_column_summary()] while computing missingness statistics. Has no impact on the returned data frame.

component

Character string selecting which part of the object to inspect. Defaults to sample metadata ('"colData"'); use '"rowData"' to inspect feature metadata of a specific assay.

assay

Optional single assay name used when 'component = "rowData"'. If omitted, the most recent assay returned by [pb_current_assay()] is used.

df

Optional data frame. When supplied, 'component' and 'assay' are ignored and the provided data frame is analysed instead.

inplace

Logical flag; when 'TRUE', the filtered metadata replaces the corresponding component inside the object. Defaults to 'FALSE' to keep the original object untouched.

Value

For data frames, a filtered data frame with attributes '"dropped_columns"', '"dropped_duplicates"', and '"dropped_missing"' describing the removal decisions. For 'ProBatchFeatures' objects, either a filtered data frame (default) or the modified object when 'inplace = TRUE'. Supplying 'df' always returns the filtered data frame and ignores 'component', 'assay', and 'inplace'.

Examples

metadata <- data.frame(
    `factor value intensity` = c(1, 2, 3),
    intensity = c(1, 2, 3),
    batch = c("A", NA, "B"),
    stringsAsFactors = FALSE,
    check.names = FALSE
)
filtered <- filter_metadata_columns(
    metadata,
    duplicate_keep = "pattern",
    duplicate_pattern = "^factor value",
    min_non_na = 2
)
names(filtered)

Identify duplicated columns in metadata or assays

Description

Compare columns after stripping attributes and normalising integer storage to double, then report pairs with matching values and 'NA' placements. The method works on plain data frames as well as on ['ProBatchFeatures'] objects by extracting the relevant annotation tables.

Usage

find_duplicated_columns(x, ...)

## Default S3 method:
find_duplicated_columns(x, ...)

## S3 method for class 'ProBatchFeatures'
find_duplicated_columns(
  x,
  component = c("colData", "rowData"),
  assay = NULL,
  df = NULL,
  ...
)

Arguments

x

A data frame-like or 'ProBatchFeatures' object to inspect.

...

Additional arguments passed to specific methods.

component

Character string selecting which part of the object to inspect. Defaults to sample metadata ('"colData"'); use '"rowData"' to inspect feature metadata of a specific assay.

assay

Optional single assay name used when 'component = "rowData"'. If omitted, the most recent assay returned by [pb_current_assay()] is used.

df

Optional data frame. When supplied, 'component' and 'assay' are ignored and the provided data frame is analysed instead.

Value

A list of character vectors (each of length two) naming duplicated column pairs. An empty list is returned when no duplicates are detected.

Examples

metadata <- data.frame(
    sample = LETTERS[1:4],
    batch = c("A", "B", "A", "B"),
    batch_copy = c("A", "B", "A", "B"),
    check.names = FALSE
)
find_duplicated_columns(metadata)

Fit a non-linear trend (currently optimized for LOESS)

Description

Fit a non-linear trend (currently optimized for LOESS)

Usage

fit_nonlinear(
  df_feature_batch,
  measure_col = "Intensity",
  order_col = "order",
  feature_id = NULL,
  batch_id = NULL,
  fit_func = "loess_regression",
  optimize_span = FALSE,
  no_fit_imputed = TRUE,
  qual_col = "m_score",
  qual_value = 2,
  min_measurements = 8,
  ...
)

Arguments

df_feature_batch

data frame containing response variable e.g. samples in order and explanatory variable e.g. measurement for a specific feature (peptide) in a specific batch

measure_col

if df_long is among the parameters, it is the column with expression/abundance/intensity; otherwise, it is used internally for consistency.

order_col

column in sample_annotation that determines sample order. It is used for in initial assessment plots (plot_sample_mean_or_boxplot) and feature-level diagnostics (feature_level_diagnostics). Can be 'NULL' if sample order is irrelevant (e.g. in genomic experiments). For more details, order definition/inference, see define_sample_order and date_to_sample_order

feature_id

the name of the feature, required for warnings

batch_id

the name of the batch, required for warnings

fit_func

method name used for the fit. Currently only "loess_regression" is accepted.

optimize_span

logical, whether to specify span or optimize it (specific entirely for LOESS regression)

no_fit_imputed

logical; when TRUE, exclude values identified by qual_col == qual_value from fitting. A matching quality column is then required.

qual_col

column to color point by certain value denoted by qual_value. Design with inferred/requant values in OpenSWATH output data, which means argument value has to be set to m_score.

qual_value

value in qual_col to color. For OpenSWATH data, this argument value has to be set to 2 (this is an m_score value for imputed values (requant values).

min_measurements

minimum length of a consecutive non-missing run required to fit a curve. Shorter runs return an all-NA fit.

...

additional parameters to be passed to the fitting function

Value

vector of fitted response values

Examples

# Load necessary datasets
data(
    list = c("example_proteome", "example_sample_annotation"),
    package = "proBatch"
)

test_peptide <- example_proteome$peptide_group_label[1]
selected_peptide <- example_proteome$peptide_group_label == test_peptide
df_selected <- example_proteome[selected_peptide, ]
selected_batch <- example_sample_annotation$MS_batch == "Batch_1"
batch_selected_df <- example_sample_annotation[selected_batch, ]
df_for_test <- merge(df_selected, batch_selected_df, by = "FullRunName")
fit_values <- fit_nonlinear(df_for_test)

# for the case where are two many missing values, no curve is fit
selected_batch <- example_sample_annotation$MS_batch == "Batch_2"
batch_selected_df <- example_sample_annotation[selected_batch, ]
df_for_test <- merge(df_selected, batch_selected_df, by = "FullRunName")
fit_values <- fit_nonlinear(df_for_test)
missing_values <- df_for_test[["m_score"]] == 2
all(fit_values[!is.na(fit_values)] ==
    df_for_test[["Intensity"]][!missing_values])

Retrieve operation chain as vector or single string "combat_on_mediannorm_on_log"

Description

Retrieve operation chain as vector or single string "combat_on_mediannorm_on_log"

Usage

get_chain(object, as_string = FALSE, assay = NULL)

Arguments

object

A ProBatchFeatures object.

as_string

logical(1). if TRUE returns the chain as a single string of the form "combat_on_mediannorm_on_log".

assay

Optional assay identifier. When supplied, derive that assay's lineage from operation-log edges. When NULL, return the legacy global chain slot.

Details

Logged lineage is validated before a chain is returned. Ambiguous or cyclic lineage causes an error, including when assay = NULL.

Value

Character vector or string describing the processing chain.

Examples

# Shared setup for ProBatchFeatures documentation examples -----------------
data("example_ecoli_data", package = "proBatch")

# Extract data
all_metadata <- example_ecoli_data$all_metadata
all_precursors <- example_ecoli_data$all_precursors
all_protein_groups <- example_ecoli_data$all_protein_groups
all_precursor_pg_match <- example_ecoli_data$all_precursor_pg_match

# Keep only essential
rm(example_ecoli_data)

# Construct a ProBatchFeatures object --------------------------------------
pbf <- ProBatchFeatures(
    data_matrix = all_precursors,
    sample_annotation = all_metadata,
    sample_id_col = "Run",
    level = "peptide"
)

# Register a custom step and evaluate it -----------------------------------
example_step <- "example_add_one"
if (!pb_has_step(example_step)) {
    pb_register_step(example_step, function(x) x + 1)
}
head(pb_eval(pbf, from = "peptide::raw", steps = example_step))

# Derived objects for downstream helpers -----------------------------------
pbf_logged <- pb_transform(
    pbf,
    from = "peptide::raw",
    steps = c("log2", "medianNorm"),
    store_fast_steps = TRUE
)

# Get information about the object ---------------------------------------
get_operation_log(pbf_logged)
get_chain(pbf_logged)
get_chain(pbf_logged, as_string = TRUE)
pb_pipeline_name(pbf_logged) # the latest pipeline
pb_pipeline_name(pbf_logged, assay = "peptide::raw")

# Access assays and matrices ------------------------------------------------
head(pb_current_assay(pbf_logged)) # the latest assay
head(pb_assay_matrix(pbf_logged)) # the latest matrix
head(pb_assay_matrix(pbf_logged, assay = "peptide::raw")) # the latest matrix
head(pb_as_wide(pbf_logged)) # the latest assay in wide format
head(pb_as_long(pbf_logged, sample_id_col = "Run")) # the latest assay in long format

# Pipeline evaluation without storing --------------------------------------
head(pb_eval(
    pbf,
    from = "peptide::raw",
    steps = c("log2", "medianNorm")
))

# Long-format constructor ---------------------------------------------------
long_pbf <- pb_as_long(pbf_logged, sample_id_col = "Run") # the latest assay in long format

ProBatchFeatures_from_long(
    df_long = long_pbf,
    sample_annotation = all_metadata,
    sample_id_col = "Run",
    feature_id_col = "feature_label",
    level = "peptide"
)


# Add proteins as a new level and link via mapping
#    all_precursor_pg_match has columns: "Precursor.Id", "Protein.Ids"
pbf <- pb_add_level(
    object = pbf,
    from = "peptide::raw",
    new_matrix = all_protein_groups,
    to_level = "protein", # will name "protein::raw" by default
    mapping_df = all_precursor_pg_match,
    from_id = "Precursor.Id",
    to_id = "Protein.Ids",
    map_strategy = "as_is"
)

# Aggregate and add levels --------------------------------------------------
pb_aggregate_level(
    pbf,
    from = "peptide::raw",
    feature_var = "ProteinID",
    new_level = "protein_new"
)

Access the operation log (structured)

Description

Access the operation log (structured)

Usage

get_operation_log(object)

Arguments

object

A ProBatchFeatures object.

Value

S4Vectors::DataFrame

Examples

# Shared setup for ProBatchFeatures documentation examples -----------------
data("example_ecoli_data", package = "proBatch")

# Extract data
all_metadata <- example_ecoli_data$all_metadata
all_precursors <- example_ecoli_data$all_precursors
all_protein_groups <- example_ecoli_data$all_protein_groups
all_precursor_pg_match <- example_ecoli_data$all_precursor_pg_match

# Keep only essential
rm(example_ecoli_data)

# Construct a ProBatchFeatures object --------------------------------------
pbf <- ProBatchFeatures(
    data_matrix = all_precursors,
    sample_annotation = all_metadata,
    sample_id_col = "Run",
    level = "peptide"
)

# Register a custom step and evaluate it -----------------------------------
example_step <- "example_add_one"
if (!pb_has_step(example_step)) {
    pb_register_step(example_step, function(x) x + 1)
}
head(pb_eval(pbf, from = "peptide::raw", steps = example_step))

# Derived objects for downstream helpers -----------------------------------
pbf_logged <- pb_transform(
    pbf,
    from = "peptide::raw",
    steps = c("log2", "medianNorm"),
    store_fast_steps = TRUE
)

# Get information about the object ---------------------------------------
get_operation_log(pbf_logged)
get_chain(pbf_logged)
get_chain(pbf_logged, as_string = TRUE)
pb_pipeline_name(pbf_logged) # the latest pipeline
pb_pipeline_name(pbf_logged, assay = "peptide::raw")

# Access assays and matrices ------------------------------------------------
head(pb_current_assay(pbf_logged)) # the latest assay
head(pb_assay_matrix(pbf_logged)) # the latest matrix
head(pb_assay_matrix(pbf_logged, assay = "peptide::raw")) # the latest matrix
head(pb_as_wide(pbf_logged)) # the latest assay in wide format
head(pb_as_long(pbf_logged, sample_id_col = "Run")) # the latest assay in long format

# Pipeline evaluation without storing --------------------------------------
head(pb_eval(
    pbf,
    from = "peptide::raw",
    steps = c("log2", "medianNorm")
))

# Long-format constructor ---------------------------------------------------
long_pbf <- pb_as_long(pbf_logged, sample_id_col = "Run") # the latest assay in long format

ProBatchFeatures_from_long(
    df_long = long_pbf,
    sample_annotation = all_metadata,
    sample_id_col = "Run",
    feature_id_col = "feature_label",
    level = "peptide"
)


# Add proteins as a new level and link via mapping
#    all_precursor_pg_match has columns: "Precursor.Id", "Protein.Ids"
pbf <- pb_add_level(
    object = pbf,
    from = "peptide::raw",
    new_matrix = all_protein_groups,
    to_level = "protein", # will name "protein::raw" by default
    mapping_df = all_precursor_pg_match,
    from_id = "Precursor.Id",
    to_id = "Protein.Ids",
    map_strategy = "as_is"
)

# Aggregate and add levels --------------------------------------------------
pb_aggregate_level(
    pbf,
    from = "peptide::raw",
    feature_var = "ProteinID",
    new_level = "protein_new"
)

Guess factors if numeric columns were not provided

Description

Derive numeric columns from factor columns if guess_factors is TRUE and numeric columns are NULL.

Usage

guess_factor_columns_if_needed(
  factor_columns,
  sample_annotation,
  guess_factors
)

Arguments

factor_columns

character vector of factor columns.

sample_annotation

data frame of sample annotations.

guess_factors

logical indicating whether to guess numeric columns.

Value

Named list containing updated factor_columns and numeric_columns.

Examples

annotation <- data.frame(
    batch = rep(c("A", "B"), 6),
    injection_order = seq_len(12)
)
guessed <- guess_factor_columns_if_needed(
    names(annotation),
    annotation,
    guess_factors = TRUE
)
guessed

Handle factor columns that are duplicated in numeric_columns

Description

Remove numeric columns from factor columns if overlap is detected.

Usage

handle_factor_numeric_overlap(factor_columns, numeric_columns)

Arguments

factor_columns

character vector of factor columns.

numeric_columns

character vector of numeric columns.

Value

A character vector containing factor_columns after any columns in numeric_columns have been removed.

Examples

factor_columns <- c("batch", "injection_order")
overlap_result <- handle_factor_numeric_overlap(
    factor_columns,
    numeric_columns = "injection_order"
)
overlap_result

Handle missing values in a numeric matrix

Description

Applies the package-wide missing-value policy used before matrix-oriented batch correction. Feature dropping never removes sample columns, including when the input happens to be square and symmetric.

Usage

handle_missing_values(
  data_matrix,
  warning_message,
  fill_the_missing = "error",
  fill_value = NULL
)

Arguments

data_matrix

Numeric feature-by-sample matrix.

warning_message

Error message used when missing values are present under the default "error" policy.

fill_the_missing

One of "error", "keep", "drop_features", or "fill". For one release, FALSE, a numeric scalar, and "remove", "rm", or "REMOVE" are translated with a deprecation warning. Explicit NULL is an error.

fill_value

Finite numeric scalar used only with fill_the_missing = "fill".

Value

A numeric matrix with the requested missing-value policy applied.

Examples

mat <- matrix(c(1, NA, 3, 4), nrow = 2)
handle_missing_values(
    mat,
    warning_message = "demo",
    fill_the_missing = "fill",
    fill_value = 0
)

Long to wide data format conversion

Description

Convert from a long data frame representation to a wide matrix representation

Usage

long_to_matrix(
  df_long,
  feature_id_col = "peptide_group_label",
  measure_col = "Intensity",
  sample_id_col = "FullRunName",
  qual_col = NULL,
  qual_value = 2
)

Arguments

df_long

data frame where each row is a single feature in a single sample. It minimally has a sample_id_col, a feature_id_col and a measure_col, but usually also an m_score (in OpenSWATH output result file). See help("example_proteome") for more details.

feature_id_col

name of the column with feature/gene/peptide/protein ID used in the long format representation df_long. In the wide formatted representation data_matrix this corresponds to the row names.

measure_col

if df_long is among the parameters, it is the column with expression/abundance/intensity; otherwise, it is used internally for consistency.

sample_id_col

name of the column in sample_annotation table, where the filenames (colnames of the data_matrix are found).

qual_col

column to color point by certain value denoted by qual_value. Design with inferred/requant values in OpenSWATH output data, which means argument value has to be set to m_score.

qual_value

value in qual_col to color. For OpenSWATH data, this argument value has to be set to 2 (this is an m_score value for imputed values (requant values).

Value

data_matrix (proBatch) like matrix (features in rows, samples in columns)

See Also

Other matrix manipulation functions: matrix_to_long()

Examples

data("example_proteome", package = "proBatch")
proteome_matrix <- long_to_matrix(example_proteome)

Wide to long conversion

Description

Convert from wide matrix to a long data frame representation

Usage

matrix_to_long(
  data_matrix,
  sample_annotation = NULL,
  feature_id_col = "peptide_group_label",
  measure_col = "Intensity",
  sample_id_col = "FullRunName",
  step = NULL
)

Arguments

data_matrix

features (in rows) vs samples (in columns) matrix, with feature IDs in rownames and file/sample names as colnames. See "example_proteome_matrix" for more details (to call the description, use help("example_proteome_matrix"))

sample_annotation

data frame with:

  1. sample_id_col (this can be repeated as row names)

  2. biological covariates

  3. technical covariates (batches etc)

. See help("example_sample_annotation")

feature_id_col

name of the column with feature/gene/peptide/protein ID used in the long format representation df_long. In the wide formatted representation data_matrix this corresponds to the row names.

measure_col

if df_long is among the parameters, it is the column with expression/abundance/intensity; otherwise, it is used internally for consistency.

sample_id_col

name of the column in sample_annotation table, where the filenames (colnames of the data_matrix are found).

step

normalization step (e.g. Raw or Normalized. Useful if consecutive steps are compared in plots. Note that in plots these are usually ordered alphabetically, so it's worth naming with numbers, e.g. 1_raw, 2_quantile

Value

df_long (proBatch) like data frame

See Also

Other matrix manipulation functions: long_to_matrix()

Examples

# Load necessary datasets
data(
    list = c("example_sample_annotation", "example_proteome_matrix"),
    package = "proBatch"
)
# Convert matrix to long format
proteome_long <- matrix_to_long(
    example_proteome_matrix,
    example_sample_annotation
)

Summarise metadata column cardinality and missingness

Description

Produce a per-column overview reporting how many distinct non-missing values appear in each column together with the number and percentage of 'NA' entries. The summary is available for plain data frames and ['ProBatchFeatures'] objects.

Usage

metadata_column_summary(x, ...)

## Default S3 method:
metadata_column_summary(x, sort = TRUE, ...)

## S3 method for class 'ProBatchFeatures'
metadata_column_summary(
  x,
  component = c("colData", "rowData"),
  assay = NULL,
  df = NULL,
  sort = TRUE,
  ...
)

Arguments

x

A data frame or 'ProBatchFeatures' object to inspect.

...

Additional arguments passed to specific methods.

sort

Logical flag indicating whether to order the resulting table by descending 'pct_NA' and then ascending 'n_unique'. Defaults to 'TRUE' to mirror console usage in batch diagnostics.

component

Character string selecting which part of the object to inspect. Defaults to sample metadata ('"colData"'); use '"rowData"' to inspect feature metadata of a specific assay.

assay

Optional single assay name used when 'component = "rowData"'. If omitted, the most recent assay returned by [pb_current_assay()] is used.

df

Optional data frame. When supplied, 'component' and 'assay' are ignored and the provided data frame is analysed instead.

Value

A data frame with columns 'colname', 'n_unique', 'n_NA', and 'pct_NA'. Percentages are expressed on a 0–100 scale. When 'sort = TRUE' the rows are ordered by decreasing missingness.

Examples

metadata <- data.frame(
    sample = LETTERS[1:4],
    batch = c("A", "B", "A", "B"),
    batch_copy = c("A", "B", "A", "B"),
    check.names = FALSE
)
metadata_column_summary(metadata)

Data normalization methods

Description

Normalization of raw (usually log-transformed) data. Normalization brings the samples to the same scale. Currently the following normalization functions are implemented:

  1. Quantile normalization: 'quantile_normalize_dm()'. Quantile normalization of the data.

  2. Median normalization: 'normalize_sample_medians_dm()'. Normalization by centering sample medians to global median of the data

Alternatively, one can call normalization function with 'normalize_data_dm()' wrapper.

Usage

quantile_normalize_dm(data_matrix)

quantile_normalize_df(
  df_long,
  feature_id_col = "peptide_group_label",
  sample_id_col = "FullRunName",
  measure_col = "Intensity",
  no_fit_imputed = TRUE,
  qual_col = NULL,
  qual_value = 2,
  keep_all = "default"
)

normalize_sample_medians_dm(
  data_matrix,
  sample_annotation = NULL,
  sample_id_col = "FullRunName",
  group_col = NULL,
  inside_batch = FALSE
)

normalize_sample_medians_df(
  df_long,
  feature_id_col = "peptide_group_label",
  sample_id_col = "FullRunName",
  measure_col = "Intensity",
  no_fit_imputed = FALSE,
  qual_col = NULL,
  qual_value = 2,
  keep_all = "default",
  sample_annotation = NULL,
  group_col = NULL,
  inside_batch = FALSE
)

normalize_data_dm(
  data_matrix,
  normalize_func = c("quantile", "medianCentering"),
  log_base = NULL,
  offset = 1
)

normalize_data_df(
  df_long,
  normalize_func = c("quantile", "medianCentering"),
  log_base = NULL,
  offset = 1,
  feature_id_col = "peptide_group_label",
  sample_id_col = "FullRunName",
  measure_col = "Intensity",
  no_fit_imputed = TRUE,
  qual_col = NULL,
  qual_value = 2,
  keep_all = "default"
)

Arguments

data_matrix

features (in rows) vs samples (in columns) matrix, with feature IDs in rownames and file/sample names as colnames. See "example_proteome_matrix" for more details (to call the description, use help("example_proteome_matrix"))

df_long

data frame where each row is a single feature in a single sample. It minimally has a sample_id_col, a feature_id_col and a measure_col, but usually also an m_score (in OpenSWATH output result file). See help("example_proteome") for more details.

feature_id_col

name of the column with feature/gene/peptide/protein ID used in the long format representation df_long. In the wide formatted representation data_matrix this corresponds to the row names.

sample_id_col

name of the column in sample_annotation table, where the filenames (colnames of the data_matrix are found).

measure_col

if df_long is among the parameters, it is the column with expression/abundance/intensity; otherwise, it is used internally for consistency.

no_fit_imputed

(logical) whether to use imputed (requant) values, as flagged in qual_col by qual_value for data transformation

qual_col

column to color point by certain value denoted by qual_value. Design with inferred/requant values in OpenSWATH output data, which means argument value has to be set to m_score.

qual_value

value in qual_col to color. For OpenSWATH data, this argument value has to be set to 2 (this is an m_score value for imputed values (requant values).

keep_all

when transforming the data (normalize, correct) - acceptable values: all/default/minimal (which set of columns be kept).

sample_annotation

optional data frame with sample-level metadata used to support within-batch normalization for data frames or matrices.

group_col

character(1); column in 'sample_annotation' (or 'df_long') identifying batches/centers for within-batch normalization.

inside_batch

logical; when 'TRUE', perform median centering within each level of 'group_col' after excluding rows that are entirely 'NA' within the corresponding subset.

normalize_func

global batch normalization method ('quantile' or 'medianCentering')

log_base

whether to log transform data matrix before normalization (e.g. 'NULL', '2' or '10')

offset

small positive number to prevent 0 conversion to -Inf

Value

The data in the same format as input (data_matrix or df_long). For long input, the pre-normalization values used by the method are stored in preNorm_<measure_col> (for example, preNorm_Intensity) and normalized values are stored in measure_col. When median normalization excludes flagged imputed values, the saved pre-normalization column contains the masked values used for fitting.

Examples

data(
    list = c("example_proteome", "example_proteome_matrix"),
    package = "proBatch"
)

# Quantile normalization:
quantile_normalized_matrix <- quantile_normalize_dm(example_proteome_matrix)

# Median centering:
median_normalized_df <- normalize_sample_medians_df(example_proteome)

# Transform the data in one go:
quantile_normalized_matrix <- normalize_data_dm(example_proteome_matrix,
    normalize_func = "quantile", log_base = 2, offset = 1
)

Add a new level from an external matrix and link to an existing assay

Description

Add a new level from an external matrix and link to an existing assay

Usage

pb_add_level(
  object,
  from,
  new_matrix,
  to_level,
  to_pipeline = NULL,
  name = NULL,
  mapping_df = NULL,
  from_id = NULL,
  to_id = NULL,
  map_strategy = c("as_is", "first", "longest"),
  link_var = "ProteinID",
  backend = c("auto", "memory", "hdf5"),
  hdf5_path = NULL
)

Arguments

object

ProBatchFeatures

from

assay name (e.g., "peptide::raw")

new_matrix

numeric matrix (features x samples)

to_level

e.g. "protein"

to_pipeline

optional pipeline name (default carries over from 'from')

name

Optional final assay name override in ⁠<level>::<pipeline>⁠ form. Stored assays and virtual operation-log targets share one result namespace. A stored-assay collision is accepted only for an exact idempotent retry with identical data, parent, mapping, and stable lineage origin; virtual-target collisions are rejected.

mapping_df

Data frame mapping from IDs to to IDs. Required only when source and target row identifiers are not identical one-to-one.

from_id

Source-ID column in mapping_df (for example, "Precursor.Id"); required with mapping_df.

to_id

Target-ID column in mapping_df (for example, "Protein.Ids"); required with mapping_df.

map_strategy

how to resolve multiple to-ids per from-id: "as_is" (error if not one-to-one), "first" (take the first exact target), or "longest" (prefer the exact target with the most semicolon-separated identifiers, then the longest string, then its first occurrence).

link_var

rowData variable name to use for linking (e.g., "ProteinID")

backend

"memory","hdf5","auto"

hdf5_path

optional filepath for HDF5Array

Value

ProBatchFeatures with new assay and link added

Examples

# Shared setup for ProBatchFeatures documentation examples -----------------
data("example_ecoli_data", package = "proBatch")

# Extract data
all_metadata <- example_ecoli_data$all_metadata
all_precursors <- example_ecoli_data$all_precursors
all_protein_groups <- example_ecoli_data$all_protein_groups
all_precursor_pg_match <- example_ecoli_data$all_precursor_pg_match

# Keep only essential
rm(example_ecoli_data)

# Construct a ProBatchFeatures object --------------------------------------
pbf <- ProBatchFeatures(
    data_matrix = all_precursors,
    sample_annotation = all_metadata,
    sample_id_col = "Run",
    level = "peptide"
)

# Register a custom step and evaluate it -----------------------------------
example_step <- "example_add_one"
if (!pb_has_step(example_step)) {
    pb_register_step(example_step, function(x) x + 1)
}
head(pb_eval(pbf, from = "peptide::raw", steps = example_step))

# Derived objects for downstream helpers -----------------------------------
pbf_logged <- pb_transform(
    pbf,
    from = "peptide::raw",
    steps = c("log2", "medianNorm"),
    store_fast_steps = TRUE
)

# Get information about the object ---------------------------------------
get_operation_log(pbf_logged)
get_chain(pbf_logged)
get_chain(pbf_logged, as_string = TRUE)
pb_pipeline_name(pbf_logged) # the latest pipeline
pb_pipeline_name(pbf_logged, assay = "peptide::raw")

# Access assays and matrices ------------------------------------------------
head(pb_current_assay(pbf_logged)) # the latest assay
head(pb_assay_matrix(pbf_logged)) # the latest matrix
head(pb_assay_matrix(pbf_logged, assay = "peptide::raw")) # the latest matrix
head(pb_as_wide(pbf_logged)) # the latest assay in wide format
head(pb_as_long(pbf_logged, sample_id_col = "Run")) # the latest assay in long format

# Pipeline evaluation without storing --------------------------------------
head(pb_eval(
    pbf,
    from = "peptide::raw",
    steps = c("log2", "medianNorm")
))

# Long-format constructor ---------------------------------------------------
long_pbf <- pb_as_long(pbf_logged, sample_id_col = "Run") # the latest assay in long format

ProBatchFeatures_from_long(
    df_long = long_pbf,
    sample_annotation = all_metadata,
    sample_id_col = "Run",
    feature_id_col = "feature_label",
    level = "peptide"
)


# Add proteins as a new level and link via mapping
#    all_precursor_pg_match has columns: "Precursor.Id", "Protein.Ids"
pbf <- pb_add_level(
    object = pbf,
    from = "peptide::raw",
    new_matrix = all_protein_groups,
    to_level = "protein", # will name "protein::raw" by default
    mapping_df = all_precursor_pg_match,
    from_id = "Precursor.Id",
    to_id = "Protein.Ids",
    map_strategy = "as_is"
)

# Aggregate and add levels --------------------------------------------------
pb_aggregate_level(
    pbf,
    from = "peptide::raw",
    feature_var = "ProteinID",
    new_level = "protein_new"
)

Aggregate features (e.g., peptide -> protein) and store as new level

Description

Aggregate features (e.g., peptide -> protein) and store as new level

Usage

pb_aggregate_level(
  object,
  from,
  feature_var,
  fun = colMedians,
  new_level = "protein",
  new_pipeline = NULL
)

Arguments

object

ProBatchFeatures

from

assay name (e.g., "peptide::raw")

feature_var

name of a column in rowData(from) holding group labels (e.g. protein IDs)

fun

summarization function (e.g., matrixStats::colMedians), or name

new_level

new level label (e.g., "protein")

new_pipeline

optional pipeline name (default carries over from 'from')

Value

ProBatchFeatures with an additional aggregated assay appended

Examples

# Shared setup for ProBatchFeatures documentation examples -----------------
data("example_ecoli_data", package = "proBatch")

# Extract data
all_metadata <- example_ecoli_data$all_metadata
all_precursors <- example_ecoli_data$all_precursors
all_protein_groups <- example_ecoli_data$all_protein_groups
all_precursor_pg_match <- example_ecoli_data$all_precursor_pg_match

# Keep only essential
rm(example_ecoli_data)

# Construct a ProBatchFeatures object --------------------------------------
pbf <- ProBatchFeatures(
    data_matrix = all_precursors,
    sample_annotation = all_metadata,
    sample_id_col = "Run",
    level = "peptide"
)

# Register a custom step and evaluate it -----------------------------------
example_step <- "example_add_one"
if (!pb_has_step(example_step)) {
    pb_register_step(example_step, function(x) x + 1)
}
head(pb_eval(pbf, from = "peptide::raw", steps = example_step))

# Derived objects for downstream helpers -----------------------------------
pbf_logged <- pb_transform(
    pbf,
    from = "peptide::raw",
    steps = c("log2", "medianNorm"),
    store_fast_steps = TRUE
)

# Get information about the object ---------------------------------------
get_operation_log(pbf_logged)
get_chain(pbf_logged)
get_chain(pbf_logged, as_string = TRUE)
pb_pipeline_name(pbf_logged) # the latest pipeline
pb_pipeline_name(pbf_logged, assay = "peptide::raw")

# Access assays and matrices ------------------------------------------------
head(pb_current_assay(pbf_logged)) # the latest assay
head(pb_assay_matrix(pbf_logged)) # the latest matrix
head(pb_assay_matrix(pbf_logged, assay = "peptide::raw")) # the latest matrix
head(pb_as_wide(pbf_logged)) # the latest assay in wide format
head(pb_as_long(pbf_logged, sample_id_col = "Run")) # the latest assay in long format

# Pipeline evaluation without storing --------------------------------------
head(pb_eval(
    pbf,
    from = "peptide::raw",
    steps = c("log2", "medianNorm")
))

# Long-format constructor ---------------------------------------------------
long_pbf <- pb_as_long(pbf_logged, sample_id_col = "Run") # the latest assay in long format

ProBatchFeatures_from_long(
    df_long = long_pbf,
    sample_annotation = all_metadata,
    sample_id_col = "Run",
    feature_id_col = "feature_label",
    level = "peptide"
)


# Add proteins as a new level and link via mapping
#    all_precursor_pg_match has columns: "Precursor.Id", "Protein.Ids"
pbf <- pb_add_level(
    object = pbf,
    from = "peptide::raw",
    new_matrix = all_protein_groups,
    to_level = "protein", # will name "protein::raw" by default
    mapping_df = all_precursor_pg_match,
    from_id = "Precursor.Id",
    to_id = "Protein.Ids",
    map_strategy = "as_is"
)

# Aggregate and add levels --------------------------------------------------
pb_aggregate_level(
    pbf,
    from = "peptide::raw",
    feature_var = "ProteinID",
    new_level = "protein_new"
)

Apply a matrix-oriented method safely

Description

Converts supported inputs to a numeric feature-by-sample matrix, aligns sample annotation by identifiers, invokes a function or registered step, validates its result, and reconstructs long data without joins or Cartesian expansion.

Usage

pb_apply_matrix_method(
  x,
  fun,
  sample_annotation = NULL,
  feature_id_col = "peptide_group_label",
  sample_id_col = "FullRunName",
  measure_col = "Intensity",
  missing = "error",
  fill_value = NULL,
  keep_all = "default",
  ...
)

Arguments

x

Numeric feature-by-sample matrix or long data frame. ProBatchFeatures objects must be transformed with pb_transform() so storage and lineage are preserved.

fun

Function or registered step identifier. The method receives the numeric matrix as its first argument. Aligned sample_annotation is also supplied when the method declares that argument or accepts ....

sample_annotation

Optional data frame aligned by sample_id_col, or by unique row names when that column is absent.

feature_id_col

Feature identifier column for long input.

sample_id_col

Sample identifier column for long input and annotation.

measure_col

Numeric measurement column for long input.

missing

Missing-value policy. "error" (the default) rejects missing values, "keep" passes them through, "drop_features" removes incomplete feature rows, and "fill" replaces missing values with fill_value.

fill_value

Finite numeric scalar used only with missing = "fill".

keep_all

Long-output column policy. "default" preserves the input columns, "all" also appends non-conflicting annotation columns, and "minimal" retains only the feature, sample, and measurement columns.

...

Additional arguments forwarded to fun. The adapter-owned data_matrix and sample_annotation arguments must not be supplied through ....

Value

A validated numeric matrix for matrix input, or a long data frame whose retained rows remain in their original relative order. If the method returns a pb_step_result, the adapter returns a pb_step_result with the validated or restored data and unchanged artifacts.

Examples

matrix_input <- matrix(
    1:6,
    nrow = 2,
    dimnames = list(c("f1", "f2"), c("s1", "s2", "s3"))
)
annotation <- data.frame(
    sample = c("s3", "s1", "s2"),
    shift = c(3, 1, 2)
)
pb_apply_matrix_method(
    matrix_input,
    function(data_matrix, sample_annotation) {
        sweep(data_matrix, 2, sample_annotation$shift, "+")
    },
    sample_annotation = annotation,
    sample_id_col = "sample"
)

Get current assay as LONG (via proBatch::matrix_to_long)

Description

Get current assay as LONG (via proBatch::matrix_to_long)

Usage

pb_as_long(
  object,
  feature_id_col = "feature_label",
  sample_id_col = "FullRunName",
  measure_col = "Intensity",
  pbf_name = pb_current_assay(object)
)

Arguments

object

A ProBatchFeatures object.

feature_id_col

Column name used for feature identifiers in the long table.

sample_id_col

Column name used for sample identifiers in the long table.

measure_col

Column name containing measured values in the long table.

pbf_name

Assay name whose intensities should be returned in long form.

Value

tibble/data.frame containing one row per feature-sample combination

Examples

# Shared setup for ProBatchFeatures documentation examples -----------------
data("example_ecoli_data", package = "proBatch")

# Extract data
all_metadata <- example_ecoli_data$all_metadata
all_precursors <- example_ecoli_data$all_precursors
all_protein_groups <- example_ecoli_data$all_protein_groups
all_precursor_pg_match <- example_ecoli_data$all_precursor_pg_match

# Keep only essential
rm(example_ecoli_data)

# Construct a ProBatchFeatures object --------------------------------------
pbf <- ProBatchFeatures(
    data_matrix = all_precursors,
    sample_annotation = all_metadata,
    sample_id_col = "Run",
    level = "peptide"
)

# Register a custom step and evaluate it -----------------------------------
example_step <- "example_add_one"
if (!pb_has_step(example_step)) {
    pb_register_step(example_step, function(x) x + 1)
}
head(pb_eval(pbf, from = "peptide::raw", steps = example_step))

# Derived objects for downstream helpers -----------------------------------
pbf_logged <- pb_transform(
    pbf,
    from = "peptide::raw",
    steps = c("log2", "medianNorm"),
    store_fast_steps = TRUE
)

# Get information about the object ---------------------------------------
get_operation_log(pbf_logged)
get_chain(pbf_logged)
get_chain(pbf_logged, as_string = TRUE)
pb_pipeline_name(pbf_logged) # the latest pipeline
pb_pipeline_name(pbf_logged, assay = "peptide::raw")

# Access assays and matrices ------------------------------------------------
head(pb_current_assay(pbf_logged)) # the latest assay
head(pb_assay_matrix(pbf_logged)) # the latest matrix
head(pb_assay_matrix(pbf_logged, assay = "peptide::raw")) # the latest matrix
head(pb_as_wide(pbf_logged)) # the latest assay in wide format
head(pb_as_long(pbf_logged, sample_id_col = "Run")) # the latest assay in long format

# Pipeline evaluation without storing --------------------------------------
head(pb_eval(
    pbf,
    from = "peptide::raw",
    steps = c("log2", "medianNorm")
))

# Long-format constructor ---------------------------------------------------
long_pbf <- pb_as_long(pbf_logged, sample_id_col = "Run") # the latest assay in long format

ProBatchFeatures_from_long(
    df_long = long_pbf,
    sample_annotation = all_metadata,
    sample_id_col = "Run",
    feature_id_col = "feature_label",
    level = "peptide"
)


# Add proteins as a new level and link via mapping
#    all_precursor_pg_match has columns: "Precursor.Id", "Protein.Ids"
pbf <- pb_add_level(
    object = pbf,
    from = "peptide::raw",
    new_matrix = all_protein_groups,
    to_level = "protein", # will name "protein::raw" by default
    mapping_df = all_precursor_pg_match,
    from_id = "Precursor.Id",
    to_id = "Protein.Ids",
    map_strategy = "as_is"
)

# Aggregate and add levels --------------------------------------------------
pb_aggregate_level(
    pbf,
    from = "peptide::raw",
    feature_var = "ProteinID",
    new_level = "protein_new"
)

Get an assay matrix (wide)

Description

Get an assay matrix (wide)

Usage

pb_as_wide(object, assay = pb_current_assay(object), name = "intensity")

Arguments

object

A ProBatchFeatures object.

assay

Assay identifier to extract; defaults to the current assay.

name

Assay entry name inside the SummarizedExperiment to return.

Value

Numeric matrix-like data corresponding to the requested assay. HDF5-backed assays may return a DelayedMatrix without coercion.

Examples

# Shared setup for ProBatchFeatures documentation examples -----------------
data("example_ecoli_data", package = "proBatch")

# Extract data
all_metadata <- example_ecoli_data$all_metadata
all_precursors <- example_ecoli_data$all_precursors
all_protein_groups <- example_ecoli_data$all_protein_groups
all_precursor_pg_match <- example_ecoli_data$all_precursor_pg_match

# Keep only essential
rm(example_ecoli_data)

# Construct a ProBatchFeatures object --------------------------------------
pbf <- ProBatchFeatures(
    data_matrix = all_precursors,
    sample_annotation = all_metadata,
    sample_id_col = "Run",
    level = "peptide"
)

# Register a custom step and evaluate it -----------------------------------
example_step <- "example_add_one"
if (!pb_has_step(example_step)) {
    pb_register_step(example_step, function(x) x + 1)
}
head(pb_eval(pbf, from = "peptide::raw", steps = example_step))

# Derived objects for downstream helpers -----------------------------------
pbf_logged <- pb_transform(
    pbf,
    from = "peptide::raw",
    steps = c("log2", "medianNorm"),
    store_fast_steps = TRUE
)

# Get information about the object ---------------------------------------
get_operation_log(pbf_logged)
get_chain(pbf_logged)
get_chain(pbf_logged, as_string = TRUE)
pb_pipeline_name(pbf_logged) # the latest pipeline
pb_pipeline_name(pbf_logged, assay = "peptide::raw")

# Access assays and matrices ------------------------------------------------
head(pb_current_assay(pbf_logged)) # the latest assay
head(pb_assay_matrix(pbf_logged)) # the latest matrix
head(pb_assay_matrix(pbf_logged, assay = "peptide::raw")) # the latest matrix
head(pb_as_wide(pbf_logged)) # the latest assay in wide format
head(pb_as_long(pbf_logged, sample_id_col = "Run")) # the latest assay in long format

# Pipeline evaluation without storing --------------------------------------
head(pb_eval(
    pbf,
    from = "peptide::raw",
    steps = c("log2", "medianNorm")
))

# Long-format constructor ---------------------------------------------------
long_pbf <- pb_as_long(pbf_logged, sample_id_col = "Run") # the latest assay in long format

ProBatchFeatures_from_long(
    df_long = long_pbf,
    sample_annotation = all_metadata,
    sample_id_col = "Run",
    feature_id_col = "feature_label",
    level = "peptide"
)


# Add proteins as a new level and link via mapping
#    all_precursor_pg_match has columns: "Precursor.Id", "Protein.Ids"
pbf <- pb_add_level(
    object = pbf,
    from = "peptide::raw",
    new_matrix = all_protein_groups,
    to_level = "protein", # will name "protein::raw" by default
    mapping_df = all_precursor_pg_match,
    from_id = "Precursor.Id",
    to_id = "Protein.Ids",
    map_strategy = "as_is"
)

# Aggregate and add levels --------------------------------------------------
pb_aggregate_level(
    pbf,
    from = "peptide::raw",
    feature_var = "ProteinID",
    new_level = "protein_new"
)

Convenience accessor for stored or virtual assay matrices

Description

Stored assays are read directly. A virtual target recorded in the operation log is replayed through its recorded canonical step and provider; replay fails with guidance if that provider is no longer registered or available. Ambiguous or cyclic operation-log lineage also causes an error.

Usage

pb_assay_matrix(object, assay = NULL, name = "intensity")

Arguments

object

A ProBatchFeatures object.

assay

Assay identifier to extract; defaults to the current assay.

name

Assay entry to read from the underlying SummarizedExperiment.

Value

Assay data with features in rows and samples in columns. In-memory assays return a matrix; HDF5-backed assays may return a DelayedMatrix.

Examples

# Shared setup for ProBatchFeatures documentation examples -----------------
data("example_ecoli_data", package = "proBatch")

# Extract data
all_metadata <- example_ecoli_data$all_metadata
all_precursors <- example_ecoli_data$all_precursors
all_protein_groups <- example_ecoli_data$all_protein_groups
all_precursor_pg_match <- example_ecoli_data$all_precursor_pg_match

# Keep only essential
rm(example_ecoli_data)

# Construct a ProBatchFeatures object --------------------------------------
pbf <- ProBatchFeatures(
    data_matrix = all_precursors,
    sample_annotation = all_metadata,
    sample_id_col = "Run",
    level = "peptide"
)

# Register a custom step and evaluate it -----------------------------------
example_step <- "example_add_one"
if (!pb_has_step(example_step)) {
    pb_register_step(example_step, function(x) x + 1)
}
head(pb_eval(pbf, from = "peptide::raw", steps = example_step))

# Derived objects for downstream helpers -----------------------------------
pbf_logged <- pb_transform(
    pbf,
    from = "peptide::raw",
    steps = c("log2", "medianNorm"),
    store_fast_steps = TRUE
)

# Get information about the object ---------------------------------------
get_operation_log(pbf_logged)
get_chain(pbf_logged)
get_chain(pbf_logged, as_string = TRUE)
pb_pipeline_name(pbf_logged) # the latest pipeline
pb_pipeline_name(pbf_logged, assay = "peptide::raw")

# Access assays and matrices ------------------------------------------------
head(pb_current_assay(pbf_logged)) # the latest assay
head(pb_assay_matrix(pbf_logged)) # the latest matrix
head(pb_assay_matrix(pbf_logged, assay = "peptide::raw")) # the latest matrix
head(pb_as_wide(pbf_logged)) # the latest assay in wide format
head(pb_as_long(pbf_logged, sample_id_col = "Run")) # the latest assay in long format

# Pipeline evaluation without storing --------------------------------------
head(pb_eval(
    pbf,
    from = "peptide::raw",
    steps = c("log2", "medianNorm")
))

# Long-format constructor ---------------------------------------------------
long_pbf <- pb_as_long(pbf_logged, sample_id_col = "Run") # the latest assay in long format

ProBatchFeatures_from_long(
    df_long = long_pbf,
    sample_annotation = all_metadata,
    sample_id_col = "Run",
    feature_id_col = "feature_label",
    level = "peptide"
)


# Add proteins as a new level and link via mapping
#    all_precursor_pg_match has columns: "Precursor.Id", "Protein.Ids"
pbf <- pb_add_level(
    object = pbf,
    from = "peptide::raw",
    new_matrix = all_protein_groups,
    to_level = "protein", # will name "protein::raw" by default
    mapping_df = all_precursor_pg_match,
    from_id = "Precursor.Id",
    to_id = "Protein.Ids",
    map_strategy = "as_is"
)

# Aggregate and add levels --------------------------------------------------
pb_aggregate_level(
    pbf,
    from = "peptide::raw",
    feature_var = "ProteinID",
    new_level = "protein_new"
)

Current (latest) assay name

Description

Current (latest) assay name

Usage

pb_current_assay(object)

Arguments

object

A ProBatchFeatures object.

Value

character(1) assay identifier for the most recently stored assay

Examples

# Shared setup for ProBatchFeatures documentation examples -----------------
data("example_ecoli_data", package = "proBatch")

# Extract data
all_metadata <- example_ecoli_data$all_metadata
all_precursors <- example_ecoli_data$all_precursors
all_protein_groups <- example_ecoli_data$all_protein_groups
all_precursor_pg_match <- example_ecoli_data$all_precursor_pg_match

# Keep only essential
rm(example_ecoli_data)

# Construct a ProBatchFeatures object --------------------------------------
pbf <- ProBatchFeatures(
    data_matrix = all_precursors,
    sample_annotation = all_metadata,
    sample_id_col = "Run",
    level = "peptide"
)

# Register a custom step and evaluate it -----------------------------------
example_step <- "example_add_one"
if (!pb_has_step(example_step)) {
    pb_register_step(example_step, function(x) x + 1)
}
head(pb_eval(pbf, from = "peptide::raw", steps = example_step))

# Derived objects for downstream helpers -----------------------------------
pbf_logged <- pb_transform(
    pbf,
    from = "peptide::raw",
    steps = c("log2", "medianNorm"),
    store_fast_steps = TRUE
)

# Get information about the object ---------------------------------------
get_operation_log(pbf_logged)
get_chain(pbf_logged)
get_chain(pbf_logged, as_string = TRUE)
pb_pipeline_name(pbf_logged) # the latest pipeline
pb_pipeline_name(pbf_logged, assay = "peptide::raw")

# Access assays and matrices ------------------------------------------------
head(pb_current_assay(pbf_logged)) # the latest assay
head(pb_assay_matrix(pbf_logged)) # the latest matrix
head(pb_assay_matrix(pbf_logged, assay = "peptide::raw")) # the latest matrix
head(pb_as_wide(pbf_logged)) # the latest assay in wide format
head(pb_as_long(pbf_logged, sample_id_col = "Run")) # the latest assay in long format

# Pipeline evaluation without storing --------------------------------------
head(pb_eval(
    pbf,
    from = "peptide::raw",
    steps = c("log2", "medianNorm")
))

# Long-format constructor ---------------------------------------------------
long_pbf <- pb_as_long(pbf_logged, sample_id_col = "Run") # the latest assay in long format

ProBatchFeatures_from_long(
    df_long = long_pbf,
    sample_annotation = all_metadata,
    sample_id_col = "Run",
    feature_id_col = "feature_label",
    level = "peptide"
)


# Add proteins as a new level and link via mapping
#    all_precursor_pg_match has columns: "Precursor.Id", "Protein.Ids"
pbf <- pb_add_level(
    object = pbf,
    from = "peptide::raw",
    new_matrix = all_protein_groups,
    to_level = "protein", # will name "protein::raw" by default
    mapping_df = all_precursor_pg_match,
    from_id = "Precursor.Id",
    to_id = "Protein.Ids",
    map_strategy = "as_is"
)

# Aggregate and add levels --------------------------------------------------
pb_aggregate_level(
    pbf,
    from = "peptide::raw",
    feature_var = "ProteinID",
    new_level = "protein_new"
)

Evaluate a pipeline and return the matrix, without storing

Description

Evaluate a pipeline and return the matrix, without storing

Usage

pb_eval(object, from, steps, funs = NULL, params_list = NULL)

Arguments

object

ProBatchFeatures

from

assay name (e.g., "peptide::raw")

steps

character vector, e.g. c("log2","medianNorm","combat")

funs

Optional same-length vector or list of functions or registered canonical names or aliases (default: steps).

params_list

list of parameter lists (same length as steps)

Value

Numeric matrix (features x samples). If a step returns a pb_step_result(), only its validated data component is returned; artifacts are not persisted by this non-storing API. Every step must retain all samples in input order and may return an input-ordered feature subset.

Examples

# Shared setup for ProBatchFeatures documentation examples -----------------
data("example_ecoli_data", package = "proBatch")

# Extract data
all_metadata <- example_ecoli_data$all_metadata
all_precursors <- example_ecoli_data$all_precursors
all_protein_groups <- example_ecoli_data$all_protein_groups
all_precursor_pg_match <- example_ecoli_data$all_precursor_pg_match

# Keep only essential
rm(example_ecoli_data)

# Construct a ProBatchFeatures object --------------------------------------
pbf <- ProBatchFeatures(
    data_matrix = all_precursors,
    sample_annotation = all_metadata,
    sample_id_col = "Run",
    level = "peptide"
)

# Register a custom step and evaluate it -----------------------------------
example_step <- "example_add_one"
if (!pb_has_step(example_step)) {
    pb_register_step(example_step, function(x) x + 1)
}
head(pb_eval(pbf, from = "peptide::raw", steps = example_step))

# Derived objects for downstream helpers -----------------------------------
pbf_logged <- pb_transform(
    pbf,
    from = "peptide::raw",
    steps = c("log2", "medianNorm"),
    store_fast_steps = TRUE
)

# Get information about the object ---------------------------------------
get_operation_log(pbf_logged)
get_chain(pbf_logged)
get_chain(pbf_logged, as_string = TRUE)
pb_pipeline_name(pbf_logged) # the latest pipeline
pb_pipeline_name(pbf_logged, assay = "peptide::raw")

# Access assays and matrices ------------------------------------------------
head(pb_current_assay(pbf_logged)) # the latest assay
head(pb_assay_matrix(pbf_logged)) # the latest matrix
head(pb_assay_matrix(pbf_logged, assay = "peptide::raw")) # the latest matrix
head(pb_as_wide(pbf_logged)) # the latest assay in wide format
head(pb_as_long(pbf_logged, sample_id_col = "Run")) # the latest assay in long format

# Pipeline evaluation without storing --------------------------------------
head(pb_eval(
    pbf,
    from = "peptide::raw",
    steps = c("log2", "medianNorm")
))

# Long-format constructor ---------------------------------------------------
long_pbf <- pb_as_long(pbf_logged, sample_id_col = "Run") # the latest assay in long format

ProBatchFeatures_from_long(
    df_long = long_pbf,
    sample_annotation = all_metadata,
    sample_id_col = "Run",
    feature_id_col = "feature_label",
    level = "peptide"
)


# Add proteins as a new level and link via mapping
#    all_precursor_pg_match has columns: "Precursor.Id", "Protein.Ids"
pbf <- pb_add_level(
    object = pbf,
    from = "peptide::raw",
    new_matrix = all_protein_groups,
    to_level = "protein", # will name "protein::raw" by default
    mapping_df = all_precursor_pg_match,
    from_id = "Precursor.Id",
    to_id = "Protein.Ids",
    map_strategy = "as_is"
)

# Aggregate and add levels --------------------------------------------------
pb_aggregate_level(
    pbf,
    from = "peptide::raw",
    feature_var = "ProteinID",
    new_level = "protein_new"
)

Test whether a transformation step is registered or available

Description

Canonical names and aliases resolve to the same registration.

Usage

pb_has_step(name, available = FALSE)

Arguments

name

One canonical step name or alias.

available

Logical scalar. If FALSE, test registration only. If TRUE, also require any recorded provider to be loaded and all declared requirements to be available.

Value

A logical scalar.

Examples

pb_has_step("medianNorm")
pb_has_step("combat", available = TRUE)

List registered transformation steps

Description

Returns canonical step names. Pattern matching considers canonical names, aliases, and display labels. Availability filtering reports current state without changing registrations.

Usage

pb_list_steps(pattern = NULL, details = FALSE, available = NULL)

Arguments

pattern

Optional regular expression used to filter canonical names, aliases, and labels.

details

Logical scalar. If FALSE, return canonical names. If TRUE, return an S4Vectors::DataFrame with provider metadata and legacy inspection columns.

available

Optional logical scalar. Use TRUE for currently available registrations, FALSE for unavailable registrations, or NULL for both.

Value

A character vector of canonical names, or an S4Vectors::DataFrame when details = TRUE. Detailed output contains step, pkg, env, and n_formals for compatibility, plus name, package, kind, label, requires, aliases, and available.

Examples

pb_list_steps()
pb_list_steps(details = TRUE)
pb_list_steps("^l")

Apply QFeatures missing-data helpers to stored assays

Description

These wrappers delegate to the corresponding QFeatures generics while ensuring that the requested assays remain part of the ProBatchFeatures object. Only assays that are already materialised can be modified. If a transformation step was applied as a "fast" step (log, log2, etc.), consider re-running it with store_fast_steps = TRUE.

Usage

pb_zeroIsNA(object, pbf_name = names(object), ...)

pb_infIsNA(object, pbf_name = names(object), ...)

pb_nNA(object, pbf_name = names(object), ...)

pb_filterNA(object, pbf_name = NULL, inplace = FALSE, final_name = NULL, ...)

pb_groupfilterNA(
  object,
  pbf_name = NULL,
  group_cols,
  min_valid = 2L,
  pNA = NULL,
  inplace = FALSE,
  final_name = NULL,
  mask_failing = TRUE,
  ...
)

Arguments

object

A ProBatchFeatures object.

pbf_name

Character vector of assay names. Defaults to names(object) - all assays.

...

Additional parameters forwarded to the underlying QFeatures method where applicable.

inplace

Logical (used by pb_filterNA() and pb_groupfilterNA()), whether to modify the object in place. Default: FALSE. If FALSE, the modified assay(s) are added to the object with final_name (if provided) or a function-specific suffix.

final_name

Character (used by pb_filterNA() and pb_groupfilterNA()), name for the modified assay(s) if inplace is FALSE. An explicit value must provide one unique, non-missing, non-empty name per selected assay. A collision with a stored assay or virtual operation-log target is accepted only for an exact idempotent retry with identical data, parent assay, and stable lineage origin. Explicit names are never recycled or disambiguated. If NULL (default), the original name(s) receive suffix ⁠_filteredNA⁠ or ⁠_groupfilteredNA⁠, respectively; generated collisions across the stored and virtual result namespace are disambiguated with numeric suffixes.

group_cols

Character vector (used by pb_groupfilterNA() only) specifying sample-annotation column(s) that define the groups within which missingness must be evaluated.

min_valid

Integer scalar (used by pb_groupfilterNA() only), minimum number of non-missing values required within each group to retain a feature. Default: 2L.

pNA

Numeric scalar (used by pb_groupfilterNA() only), maximum proportion of missing values allowed within each group to retain a feature. Must be in the range ⁠[0, 1]⁠. If both min_valid and pNA are provided, the stricter requirement is applied per group by enforcing the larger minimum number of observed values implied by either threshold.

mask_failing

Logical scalar (used by pb_groupfilterNA() only). When TRUE (default), values in groups that did not pass the missingness threshold are set to NA. When FALSE, the original values in failing groups are kept as-is (the feature is still retained if it passes in at least one group).

Details

For grouped filtering, features are retained if they meet the missingness criteria in at least one group defined by group_cols. When mask_failing = TRUE (the default), the values in groups where the feature did not pass the threshold are replaced with NA.

With in-place pb_filterNA(), QFeatures preserves valid assay links and prunes their hits to the retained features. In-place pb_groupfilterNA() replaces the assay directly and may remove affected links when feature rows change; QFeatures warns when this occurs. Use inplace = FALSE to keep existing links unchanged.

Value

pb_zeroIsNA(), pb_infIsNA(), pb_filterNA() and pb_groupfilterNA() return the updated ProBatchFeatures object. For one assay, pb_nNA() returns the corresponding QFeatures::nNA() result (a list of DataFrames). For multiple assays it returns a named outer list with one such result per assay and a combined nNA DataFrame.

Examples

values <- matrix(
    c(0, 1, 2, Inf, 4, 5, 6, 7, 8),
    nrow = 3,
    byrow = TRUE,
    dimnames = list(
        paste0("feature", 1:3),
        paste0("sample", 1:3)
    )
)
annotation <- data.frame(sample = colnames(values))
pbf <- ProBatchFeatures(
    values,
    sample_annotation = annotation,
    sample_id_col = "sample"
)
pbf <- pb_zeroIsNA(pbf, "feature::raw")
pbf <- pb_infIsNA(pbf, "feature::raw")
pb_nNA(pbf, "feature::raw")$nNA

filtered <- pb_filterNA(
    pbf,
    pbf_name = "feature::raw",
    pNA = 0
)
rownames(filtered[["feature::raw_filteredNA"]])

Pretty pipeline name derived from the assay

Description

Pretty pipeline name derived from the assay

Usage

pb_pipeline_name(object, assay = pb_current_assay(object))

Arguments

object

ProBatchFeatures

assay

character(1) assay name; defaults to current assay

Details

The operation-log lineage must be unambiguous and acyclic.

Value

character(1) pipeline string like "combat_on_medianNorm_on_log2_on_raw" or "raw"

Examples

# Shared setup for ProBatchFeatures documentation examples -----------------
data("example_ecoli_data", package = "proBatch")

# Extract data
all_metadata <- example_ecoli_data$all_metadata
all_precursors <- example_ecoli_data$all_precursors
all_protein_groups <- example_ecoli_data$all_protein_groups
all_precursor_pg_match <- example_ecoli_data$all_precursor_pg_match

# Keep only essential
rm(example_ecoli_data)

# Construct a ProBatchFeatures object --------------------------------------
pbf <- ProBatchFeatures(
    data_matrix = all_precursors,
    sample_annotation = all_metadata,
    sample_id_col = "Run",
    level = "peptide"
)

# Register a custom step and evaluate it -----------------------------------
example_step <- "example_add_one"
if (!pb_has_step(example_step)) {
    pb_register_step(example_step, function(x) x + 1)
}
head(pb_eval(pbf, from = "peptide::raw", steps = example_step))

# Derived objects for downstream helpers -----------------------------------
pbf_logged <- pb_transform(
    pbf,
    from = "peptide::raw",
    steps = c("log2", "medianNorm"),
    store_fast_steps = TRUE
)

# Get information about the object ---------------------------------------
get_operation_log(pbf_logged)
get_chain(pbf_logged)
get_chain(pbf_logged, as_string = TRUE)
pb_pipeline_name(pbf_logged) # the latest pipeline
pb_pipeline_name(pbf_logged, assay = "peptide::raw")

# Access assays and matrices ------------------------------------------------
head(pb_current_assay(pbf_logged)) # the latest assay
head(pb_assay_matrix(pbf_logged)) # the latest matrix
head(pb_assay_matrix(pbf_logged, assay = "peptide::raw")) # the latest matrix
head(pb_as_wide(pbf_logged)) # the latest assay in wide format
head(pb_as_long(pbf_logged, sample_id_col = "Run")) # the latest assay in long format

# Pipeline evaluation without storing --------------------------------------
head(pb_eval(
    pbf,
    from = "peptide::raw",
    steps = c("log2", "medianNorm")
))

# Long-format constructor ---------------------------------------------------
long_pbf <- pb_as_long(pbf_logged, sample_id_col = "Run") # the latest assay in long format

ProBatchFeatures_from_long(
    df_long = long_pbf,
    sample_annotation = all_metadata,
    sample_id_col = "Run",
    feature_id_col = "feature_label",
    level = "peptide"
)


# Add proteins as a new level and link via mapping
#    all_precursor_pg_match has columns: "Precursor.Id", "Protein.Ids"
pbf <- pb_add_level(
    object = pbf,
    from = "peptide::raw",
    new_matrix = all_protein_groups,
    to_level = "protein", # will name "protein::raw" by default
    mapping_df = all_precursor_pg_match,
    from_id = "Precursor.Id",
    to_id = "Protein.Ids",
    map_strategy = "as_is"
)

# Aggregate and add levels --------------------------------------------------
pb_aggregate_level(
    pbf,
    from = "peptide::raw",
    feature_var = "ProteinID",
    new_level = "protein_new"
)

Register a provider-neutral transformation step

Description

Registers one canonical step and optional aliases for use by pb_transform(), pb_eval(), and pb_apply_matrix_method(). Registration records metadata only: it does not install, load, or probe a provider or any optional engine. Repeating an identical registration is a no-op. A different registration that collides with an existing canonical name or alias is rejected; refresh a provider with pb_unregister_steps() followed by registration.

Usage

pb_register_step(
  name,
  fun,
  package = NULL,
  kind = "transform",
  requires = character(),
  aliases = character(),
  label = name
)

Arguments

name

One non-missing, non-empty canonical step name.

fun

Function implementing the step. It receives a numeric matrix as its first argument and may declare a sample_annotation argument. It must return a numeric matrix or a pb_step_result().

package

Optional provider package name. When omitted, the function environment is used to infer a provider without loading a package. Functions without a package namespace are ordinary user registrations.

kind

One non-missing, non-empty step-kind label.

requires

Character vector naming packages required when the step is invoked.

aliases

Character vector of alternative names for name.

label

One non-missing, non-empty display label.

Value

TRUE, invisibly.

Examples

# Shared setup for ProBatchFeatures documentation examples -----------------
data("example_ecoli_data", package = "proBatch")

# Extract data
all_metadata <- example_ecoli_data$all_metadata
all_precursors <- example_ecoli_data$all_precursors
all_protein_groups <- example_ecoli_data$all_protein_groups
all_precursor_pg_match <- example_ecoli_data$all_precursor_pg_match

# Keep only essential
rm(example_ecoli_data)

# Construct a ProBatchFeatures object --------------------------------------
pbf <- ProBatchFeatures(
    data_matrix = all_precursors,
    sample_annotation = all_metadata,
    sample_id_col = "Run",
    level = "peptide"
)

# Register a custom step and evaluate it -----------------------------------
example_step <- "example_add_one"
if (!pb_has_step(example_step)) {
    pb_register_step(example_step, function(x) x + 1)
}
head(pb_eval(pbf, from = "peptide::raw", steps = example_step))

# Derived objects for downstream helpers -----------------------------------
pbf_logged <- pb_transform(
    pbf,
    from = "peptide::raw",
    steps = c("log2", "medianNorm"),
    store_fast_steps = TRUE
)

# Get information about the object ---------------------------------------
get_operation_log(pbf_logged)
get_chain(pbf_logged)
get_chain(pbf_logged, as_string = TRUE)
pb_pipeline_name(pbf_logged) # the latest pipeline
pb_pipeline_name(pbf_logged, assay = "peptide::raw")

# Access assays and matrices ------------------------------------------------
head(pb_current_assay(pbf_logged)) # the latest assay
head(pb_assay_matrix(pbf_logged)) # the latest matrix
head(pb_assay_matrix(pbf_logged, assay = "peptide::raw")) # the latest matrix
head(pb_as_wide(pbf_logged)) # the latest assay in wide format
head(pb_as_long(pbf_logged, sample_id_col = "Run")) # the latest assay in long format

# Pipeline evaluation without storing --------------------------------------
head(pb_eval(
    pbf,
    from = "peptide::raw",
    steps = c("log2", "medianNorm")
))

# Long-format constructor ---------------------------------------------------
long_pbf <- pb_as_long(pbf_logged, sample_id_col = "Run") # the latest assay in long format

ProBatchFeatures_from_long(
    df_long = long_pbf,
    sample_annotation = all_metadata,
    sample_id_col = "Run",
    feature_id_col = "feature_label",
    level = "peptide"
)


# Add proteins as a new level and link via mapping
#    all_precursor_pg_match has columns: "Precursor.Id", "Protein.Ids"
pbf <- pb_add_level(
    object = pbf,
    from = "peptide::raw",
    new_matrix = all_protein_groups,
    to_level = "protein", # will name "protein::raw" by default
    mapping_df = all_precursor_pg_match,
    from_id = "Precursor.Id",
    to_id = "Protein.Ids",
    map_strategy = "as_is"
)

# Aggregate and add levels --------------------------------------------------
pb_aggregate_level(
    pbf,
    from = "peptide::raw",
    feature_var = "ProteinID",
    new_level = "protein_new"
)

Return transformed data with structured method artifacts

Description

Provider-neutral transformation methods can use this result type to return transformed data together with artifacts such as model fits, latent factors, or diagnostics. Matrix-oriented Core APIs validate the data component independently of the artifacts.

Usage

pb_step_result(data, artifacts = list())

Arguments

data

Transformed data produced by a method.

artifacts

A list of structured artifacts associated with data.

Value

An object of class pb_step_result with data and artifacts components.

Examples

result <- pb_step_result(
    matrix(1:4, nrow = 2),
    artifacts = list(converged = TRUE)
)
result$data
result$artifacts

Subset samples using ProBatchFeatures metadata.

Description

Resolve sample metadata from colData(object), build a column mask, and delegate to the subclass-preserving [ method so every assay is subset consistently.

Usage

pb_subset_samples(
  object,
  sample_id_col = "FullRunName",
  subset_by = sample_id_col,
  subset_values
)

Arguments

object

A ProBatchFeatures object.

sample_id_col

Character scalar naming the sample identifier column in colData(object). When the column is absent, row names are used.

subset_by

Character scalar naming the metadata column used for filtering. Defaults to sample_id_col.

subset_values

Values to retain from subset_by.

Value

A ProBatchFeatures object restricted to the selected samples.

Examples

data(example_proteome_matrix, package = "proBatch")
data(example_sample_annotation, package = "proBatch")
sample_annotation <- example_sample_annotation
sample_annotation$Group <- rep(
    c("Pool", "Study"),
    length.out = nrow(sample_annotation)
)
pbf <- ProBatchFeatures(
    data_matrix = example_proteome_matrix,
    sample_annotation = sample_annotation,
    sample_id_col = "FullRunName"
)
pb_subset_samples(
    pbf,
    sample_id_col = "FullRunName",
    subset_by = "Group",
    subset_values = "Pool"
)

Compute a pipeline and optionally store only the final result

Description

Compute a pipeline and optionally store only the final result

Usage

pb_transform(
  object,
  from,
  steps,
  funs = NULL,
  params_list = NULL,
  level = NULL,
  store_fast_steps = FALSE,
  fast_steps = c("log", "log2", "medianNorm"),
  store_intermediate = FALSE,
  final_name = NULL,
  backend = c("auto", "memory", "hdf5"),
  hdf5_path = NULL
)

Arguments

object

A ProBatchFeatures object.

from

Assay name to start the pipeline from.

steps

character vector, e.g. c("log2","medianNorm","combat")

funs

Optional same-length vector or list of functions or registered canonical names or aliases (default: steps). Registered aliases are resolved to their canonical names for operation logging.

params_list

list of parameter lists (same length as steps)

level

Optional level label to assign to the generated assay(s).

store_fast_steps

Logical; if FALSE, intermediate steps listed in fast_steps are computed but not stored. A final log or log2 step is also virtual unless final_name is supplied. Setting store_fast_steps = TRUE materializes it; other final steps are materialized regardless.

fast_steps

Steps treated as fast (default: c("log", "log2", "medianNorm")).

store_intermediate

logical; if TRUE store every step (overrides fast behavior)

final_name

Optional final assay name override in ⁠<level>::<pipeline>⁠ form. It must differ from from. Stored assays and virtual operation-log targets share one result namespace, so a conflicting explicit name is rejected rather than disambiguated unless the request is an exact idempotent retry. Supplying a name materializes the final result even for an otherwise ephemeral log step.

backend

"memory","hdf5","auto"

hdf5_path

Optional file path used when backend = "hdf5".

Details

Registered steps record their canonical name and provider package. When a step returns pb_step_result() and its assay is materialized, the result's artifacts are stored in that assay's metadata under pb_step_artifacts. Step results must retain all samples in input order; an input-ordered feature subset is allowed.

Value

ProBatchFeatures with the requested pipeline added (as log and/or assay)

Examples

# Shared setup for ProBatchFeatures documentation examples -----------------
data("example_ecoli_data", package = "proBatch")

# Extract data
all_metadata <- example_ecoli_data$all_metadata
all_precursors <- example_ecoli_data$all_precursors
all_protein_groups <- example_ecoli_data$all_protein_groups
all_precursor_pg_match <- example_ecoli_data$all_precursor_pg_match

# Keep only essential
rm(example_ecoli_data)

# Construct a ProBatchFeatures object --------------------------------------
pbf <- ProBatchFeatures(
    data_matrix = all_precursors,
    sample_annotation = all_metadata,
    sample_id_col = "Run",
    level = "peptide"
)

# Register a custom step and evaluate it -----------------------------------
example_step <- "example_add_one"
if (!pb_has_step(example_step)) {
    pb_register_step(example_step, function(x) x + 1)
}
head(pb_eval(pbf, from = "peptide::raw", steps = example_step))

# Derived objects for downstream helpers -----------------------------------
pbf_logged <- pb_transform(
    pbf,
    from = "peptide::raw",
    steps = c("log2", "medianNorm"),
    store_fast_steps = TRUE
)

# Get information about the object ---------------------------------------
get_operation_log(pbf_logged)
get_chain(pbf_logged)
get_chain(pbf_logged, as_string = TRUE)
pb_pipeline_name(pbf_logged) # the latest pipeline
pb_pipeline_name(pbf_logged, assay = "peptide::raw")

# Access assays and matrices ------------------------------------------------
head(pb_current_assay(pbf_logged)) # the latest assay
head(pb_assay_matrix(pbf_logged)) # the latest matrix
head(pb_assay_matrix(pbf_logged, assay = "peptide::raw")) # the latest matrix
head(pb_as_wide(pbf_logged)) # the latest assay in wide format
head(pb_as_long(pbf_logged, sample_id_col = "Run")) # the latest assay in long format

# Pipeline evaluation without storing --------------------------------------
head(pb_eval(
    pbf,
    from = "peptide::raw",
    steps = c("log2", "medianNorm")
))

# Long-format constructor ---------------------------------------------------
long_pbf <- pb_as_long(pbf_logged, sample_id_col = "Run") # the latest assay in long format

ProBatchFeatures_from_long(
    df_long = long_pbf,
    sample_annotation = all_metadata,
    sample_id_col = "Run",
    feature_id_col = "feature_label",
    level = "peptide"
)


# Add proteins as a new level and link via mapping
#    all_precursor_pg_match has columns: "Precursor.Id", "Protein.Ids"
pbf <- pb_add_level(
    object = pbf,
    from = "peptide::raw",
    new_matrix = all_protein_groups,
    to_level = "protein", # will name "protein::raw" by default
    mapping_df = all_precursor_pg_match,
    from_id = "Precursor.Id",
    to_id = "Protein.Ids",
    map_strategy = "as_is"
)

# Aggregate and add levels --------------------------------------------------
pb_aggregate_level(
    pbf,
    from = "peptide::raw",
    feature_var = "ProteinID",
    new_level = "protein_new"
)

Unregister all transformation steps from one provider

Description

Removes every canonical registration and alias owned by package. Calling the function when the provider owns no registrations is a no-op.

Usage

pb_unregister_steps(package)

Arguments

package

One non-missing, non-empty provider package name.

Value

The removed canonical names, invisibly.

Examples

local({
    provider <- "proBatchExampleProvider"
    on.exit(pb_unregister_steps(provider), add = TRUE)
    pb_register_step(
        "example_unregister_identity",
        function(x) x,
        package = provider,
        aliases = "example_unregister_no_change"
    )
    alias_registered <- pb_has_step("example_unregister_no_change")
    removed <- pb_unregister_steps(provider)
    c(
        alias_registered = alias_registered,
        alias_removed = !pb_has_step("example_unregister_no_change"),
        canonical_removed = identical(
            removed,
            "example_unregister_identity"
        )
    )
})

Visualise correlation matrix

Description

recommended for heatmap-type visualisation of correlation matrix with <100 items. With >50 samples and ~10 replicate pairs distribution plots may be more informative.

Usage

plot_corr_matrix(
  corr_matrix,
  annotation = NULL,
  annotation_id_col = "FullRunName",
  factors_to_plot = NULL,
  cluster_rows = FALSE,
  cluster_cols = FALSE,
  heatmap_color = colorRampPalette(rev(brewer.pal(n = 7, name = "RdYlBu")))(100),
  color_list = NULL,
  filename = NULL,
  width = 7,
  height = 7,
  units = c("cm", "in", "mm"),
  plot_title = NULL,
  ...
)

Arguments

corr_matrix

square correlation matrix

annotation

data frame with peptide_annotation for protein correlation heatmap or sample_annotation for sample correlation heatmap

annotation_id_col

feature_id_col for protein correlation heatmap or sample_id_col for sample correlation heatmap

factors_to_plot

vector of technical and biological covariates to be plotted in this diagnostic plot (assumed to be present in sample_annotation)

cluster_rows

logical; whether rows should be clustered.

cluster_cols

logical; whether columns should be clustered.

heatmap_color

vector of colors used in heatmap.

color_list

list, as returned by sample_annotation_to_colors, where each item contains a color vector for each factor to be mapped to the color.

filename

path where the results are saved. If null the object is returned to the active window; otherwise, the object is save into the file. Currently only pdf and png format is supported

width

option determining the output image width

height

option determining the output image height

units

units: 'cm', 'in' or 'mm'

plot_title

title of the plot (e.g., processing step + representation level (fragments, transitions, proteins) + purpose (meanplot/corrplot etc))

...

parameters for the pheatmap visualisation, for details see examples and help to corresponding functions

Details

Plot correlation of selected samples or peptides

Value

pheatmap object

See Also

pheatmap, plot_sample_corr_distribution, plot_peptide_corr_distribution

Examples

data("example_proteome_matrix", package = "proBatch")
peptides <- c("10231_QDVDVWLWQQEGSSK_2", "10768_RLESELDGLR_2")
data_matrix_sub <- example_proteome_matrix[peptides, ]
corr_matrix <- cor(t(data_matrix_sub), use = "complete.obs")
corr_matrix_plot <- plot_corr_matrix(corr_matrix)

Plot CV distribution to compare various steps of the analysis

Description

Plot CV distribution to compare various steps of the analysis

Usage

plot_CV_distr(
  df_long,
  sample_annotation = NULL,
  feature_id_col = "peptide_group_label",
  sample_id_col = "FullRunName",
  measure_col = "Intensity",
  biospecimen_id_col = "EarTag",
  batch_col = NULL,
  unlog = TRUE,
  log_base = 2,
  offset = 1,
  plot_title = NULL,
  filename = NULL,
  theme = "classic",
  pbf_name = NULL
)

Arguments

df_long

as in df_long for the rest of the package, but, when it has entries for intensity, represented in measure_col for several steps, e.g. raw, normalized, batch corrected data, as seen in column Step, then multi-step CV comparison can be carried out.

sample_annotation

data frame with:

  1. sample_id_col (this can be repeated as row names)

  2. biological covariates

  3. technical covariates (batches etc)

. See help("example_sample_annotation")

feature_id_col

name of the column with feature/gene/peptide/protein ID used in the long format representation df_long. In the wide formatted representation data_matrix this corresponds to the row names.

sample_id_col

name of the column in sample_annotation table, where the filenames (colnames of the data_matrix are found).

measure_col

if df_long is among the parameters, it is the column with expression/abundance/intensity; otherwise, it is used internally for consistency.

biospecimen_id_col

column in sample_annotation that defines a unique bio ID, which is usually a combination of conditions or groups. Tip: if such ID is absent, but can be defined from several columns, create new biospecimen_id column

batch_col

column in sample_annotation that should be used for batch comparison (or other, non-batch factor to be mapped to color in plots).

unlog

(logical) whether to reverse log transformation of the original data

log_base

base of the logarithm for transformation

offset

small positive number to prevent 0 conversion to -Inf

plot_title

title of the plot (e.g., processing step + representation level (fragments, transitions, proteins) + purpose (meanplot/corrplot etc))

filename

path where the results are saved. If null the object is returned to the active window; otherwise, the object is save into the file. Currently only pdf and png format is supported

theme

ggplot theme, by default classic. Can be easily overridden

pbf_name

Assay name to transform when 'x' is a 'ProBatchFeatures'.

Details

If 'batch_col' is supplied and per-batch CV is available, 'plot_CV_distr()' plots 'CV_perBatch' across batches. Otherwise it plots 'CV_total'.

Value

ggplot object with the boxplot of CVs on one or several steps

Examples

data(
    list = c("example_sample_annotation", "example_proteome"),
    package = "proBatch"
)
CV_plot <- plot_CV_distr(example_proteome,
    sample_annotation = example_sample_annotation,
    measure_col = "Intensity", batch_col = "MS_batch",
    plot_title = NULL, filename = NULL, theme = "classic"
)

Plot the distribution (boxplots) of per-batch per-step CV of features

Description

Plot the distribution (boxplots) of per-batch per-step CV of features

Usage

plot_CV_distr.df(
  CV_df,
  plot_title = NULL,
  filename = NULL,
  theme = "classic",
  log_y_scale = TRUE,
  batch_col = NULL,
  value_col = c("auto", "CV_total", "CV_perBatch")
)

Arguments

CV_df

data frame with Total CV for each feature & (optionally) per-batch CV

plot_title

title of the plot (e.g., processing step + representation level (fragments, transitions, proteins) + purpose (meanplot/corrplot etc))

filename

path where the results are saved. If null the object is returned to the active window; otherwise, the object is save into the file. Currently only pdf and png format is supported

theme

ggplot theme, by default classic. Can be easily overridden

log_y_scale

(logical) whether to display the CV on log-scale

batch_col

optional batch column in CV_df; used when plotting CV_perBatch.

value_col

which CV column to plot: "auto" (default), "CV_total", or "CV_perBatch".

Value

ggplot object

Examples

cv_example <- data.frame(
    Step = c("raw", "raw", "raw"),
    CV_total = c(10, 15, 12)
)
plot_CV_distr.df(cv_example, log_y_scale = FALSE)

Plot grouped missing-value heatmap(s)

Description

Visualise assay missingness after collapsing samples into groups defined by one or more metadata columns. Each heatmap cell stores the fraction of samples in the group with an observed value. The annotation bar mirrors the grouping variables, so multiple 'color_by' columns appear as multiple annotation tracks.

Usage

plot_grouped_NA_heatmap(x, ...)

## Default S3 method:
plot_grouped_NA_heatmap(
  x,
  sample_annotation = NULL,
  sample_id_col = NULL,
  color_by = NULL,
  label_by = NULL,
  cluster_samples = TRUE,
  cluster_features = TRUE,
  show_row_dend = TRUE,
  show_column_dend = FALSE,
  missing_color = "black",
  valid_color = "grey90",
  col_vector = NULL,
  drop_complete = TRUE,
  draw = TRUE,
  main = NULL,
  force_binarization = FALSE,
  ...
)

## S3 method for class 'ProBatchFeatures'
plot_grouped_NA_heatmap(
  x,
  pbf_name = NULL,
  color_by = NULL,
  label_by = NULL,
  sample_id_col = NULL,
  cluster_samples = TRUE,
  cluster_features = TRUE,
  show_row_dend = TRUE,
  show_column_dend = FALSE,
  missing_color = "black",
  valid_color = "grey90",
  col_vector = NULL,
  drop_complete = TRUE,
  nrow = NULL,
  ncol = NULL,
  draw = TRUE,
  use_subset = TRUE,
  force_binarization = FALSE,
  ...
)

Arguments

x

A data container. For the 'ProBatchFeatures' method this must be a 'ProBatchFeatures' object. The default method accepts any matrix-like input (including 'SummarizedExperiment').

...

Additional parameters forwarded to [pheatmap::pheatmap()].

sample_annotation

Optional data frame with sample-level metadata. Row names (or the column specified via 'sample_id_col') must match the column names of the intensity matrix. When 'x' is a 'ProBatchFeatures' object the sample annotation defaults to 'as.data.frame(colData(x))'.

sample_id_col

Optional column in 'sample_annotation' providing unique sample identifiers. Use this when the data frame lacks row names matching the assay column names.

color_by

One or more column names in 'sample_annotation' used both to define the sample groups and to annotate the grouped heatmap columns. '.group_key', '.group_size', and '.group_label' are reserved for generated group metadata.

label_by

Optional grouping column used for the grouped column labels. The default, 'NULL', displays generated labels containing all grouping values and the group size. The generated label column is named '.group_label'.

cluster_samples, cluster_features

Logical flags controlling whether the heatmap columns/rows are clustered.

show_row_dend, show_column_dend

Logical, whether dendrograms should be drawn for the clustered rows/columns.

missing_color, valid_color

Colours used for missing ('0') and observed ('1') values respectively.

col_vector

Optional vector of colours that will be recycled to colour the unique values of 'color_by'.

drop_complete

Logical, drop features without any missing values before plotting. Defaults to 'TRUE' to focus on missingness patterns.

draw

Logical, draw the heatmap(s). Set to 'FALSE' to obtain the grob(s) without plotting. For multiple assays, the arranged grob is returned invisibly when 'draw = TRUE'.

main

Optional title passed to [pheatmap::pheatmap()] for single assays.

force_binarization

Optional threshold used to binarize grouped observed fractions. Use 'FALSE' (default) to retain fractions, 'TRUE' to use '0.5', or a single numeric value in '[0, 1]' to mark group cells with observed fraction greater than or equal to the threshold as present and lower values as missing.

pbf_name

Character scalar or vector with assay names to plot. When 'NULL', the most recent assay returned by [pb_current_assay()] is used. Only used by the 'ProBatchFeatures' method.

nrow, ncol

Integers controlling the layout when multiple assays are plotted. If both are 'NULL', a roughly square layout is chosen automatically.

use_subset

Logical; for 'ProBatchFeatures' inputs, randomly subset assays over 5000 rows. All sample columns are retained so grouped fractions and group sizes remain exact.

Value

For a single assay the returned value is the 'pheatmap' object. When multiple assays are requested a list is returned invisibly with elements 'grob' (the arranged heatmaps) and 'heatmaps' (individual 'pheatmap' objects). Assays without incomplete group-level patterns are skipped with a warning.

Examples

missing_matrix <- matrix(
    seq_len(24),
    nrow = 6,
    dimnames = list(
        paste0("feature_", seq_len(6)),
        paste0("sample_", seq_len(4))
    )
)
missing_matrix[cbind(seq_len(4), seq_len(4))] <- NA
sample_annotation <- data.frame(
    condition = rep(c("control", "treated"), each = 2),
    row.names = colnames(missing_matrix)
)
grouped_heatmap <- plot_grouped_NA_heatmap(
    missing_matrix,
    sample_annotation = sample_annotation,
    color_by = "condition",
    cluster_samples = FALSE,
    cluster_features = FALSE,
    draw = FALSE
)

Plot the heatmap of samples (cols) vs features (rows)

Description

Plot the heatmap of samples (cols) vs features (rows)

Usage

## Default S3 method:
plot_heatmap_diagnostic(
  data_matrix,
  sample_annotation = NULL,
  sample_id_col = "FullRunName",
  factors_to_plot = NULL,
  fill_the_missing = -1,
  color_for_missing = "black",
  heatmap_color = colorRampPalette(rev(brewer.pal(n = 7, name = "RdYlBu")))(100),
  cluster_rows = TRUE,
  cluster_cols = FALSE,
  color_list = NULL,
  peptide_annotation = NULL,
  feature_id_col = NULL,
  factors_of_feature_ann = NULL,
  color_list_features = NULL,
  filename = NULL,
  width = 7,
  height = 7,
  units = c("cm", "in", "mm"),
  plot_title = NULL,
  ...
)

## S3 method for class 'ProBatchFeatures'
plot_heatmap_diagnostic(
  data_matrix,
  pbf_name = NULL,
  sample_annotation = NULL,
  sample_id_col = "FullRunName",
  peptide_annotation = NULL,
  feature_id_col = "peptide_group_label",
  plot_title = NULL,
  return_gridExtra = FALSE,
  plot_ncol = NULL,
  ...
)

Arguments

data_matrix

Input object: matrix-like data or a ProBatchFeatures instance.

sample_annotation

data frame with:

  1. sample_id_col (this can be repeated as row names)

  2. biological covariates

  3. technical covariates (batches etc)

. See help("example_sample_annotation")

sample_id_col

name of the column in sample_annotation table, where the filenames (colnames of the data_matrix are found).

factors_to_plot

vector of technical and biological factors to be plotted in this diagnostic plot (assumed to be present in sample_annotation)

fill_the_missing

numeric value that the missing values are substituted with, or NULL if features with missing values are to be excluded.

color_for_missing

special color to make missing values. Usually black or white, depending on heatmap_color

heatmap_color

vector of colors used in heatmap (typically a gradient)

cluster_rows

boolean value determining if rows should be clustered

cluster_cols

boolean value determining if columns should be clustered

color_list

list, as returned by sample_annotation_to_colors, where each item contains a color vector for each factor to be mapped to the color.

peptide_annotation

long format data frame with peptide ID and their corresponding protein and/or gene annotations. See help("example_peptide_annotation").

feature_id_col

name of the column with feature/gene/peptide/protein ID used in the long format representation df_long. In the wide formatted representation data_matrix this corresponds to the row names.

factors_of_feature_ann

vector of factors that characterize features, as listed in peptide_annotation

color_list_features

list, as returned by sample_annotation_to_colors, but mapping peptide_annotation where each item contains a color vector for each factor to be mapped to the color.

filename

path where the results are saved. If null the object is returned to the active window; otherwise, the object is save into the file. Currently only pdf and png format is supported

width

option determining the output image width

height

option determining the output image height

units

units: 'cm', 'in' or 'mm'

plot_title

title of the plot (e.g., processing step + representation level (fragments, transitions, proteins) + purpose (meanplot/corrplot etc))

...

other parameters of link[pheatmap]{pheatmap}

pbf_name

Assay name(s) used when data_matrix is a ProBatchFeatures.

return_gridExtra

Logical; for multiple assays, return an invisible list with grob, the arranged plot, and plots, the named per-assay results.

plot_ncol

Number of columns when arranging multiple assay plots.

Value

For matrix input or one selected ProBatchFeatures assay, a pheatmap object. For multiple assays, an arranged plot is returned invisibly; with return_gridExtra = TRUE, an invisible list containing grob and the named per-assay plots is returned.

See Also

sample_annotation_to_colors, pheatmap

Examples

# Load necessary datasets
data(
    list = c("example_proteome_matrix", "example_sample_annotation"),
    package = "proBatch"
)

# Use a smaller subset for the example
example_proteome_matrix_small <- example_proteome_matrix[1:50, ]

log_transformed_matrix <- log_transform_dm(example_proteome_matrix_small)
color_list <- sample_annotation_to_colors(example_sample_annotation,
    factor_columns = c(
        "MS_batch", "EarTag", "Strain",
        "Diet", "digestion_batch", "Sex"
    ),
    numeric_columns = c("DateTime", "order")
)

heatmap_plot <- plot_heatmap_diagnostic(log_transformed_matrix,
    example_sample_annotation,
    factors_to_plot = c("MS_batch", "digestion_batch", "Diet", "DateTime"),
    cluster_cols = TRUE, cluster_rows = FALSE,
    color_list = color_list, # can be NULL
    show_rownames = FALSE, show_colnames = FALSE
)

Plot the heatmap

Description

Plot the heatmap

Usage

## Default S3 method:
plot_heatmap_generic(
  data_matrix,
  column_annotation_df = NULL,
  row_annotation_df = NULL,
  col_ann_id_col = NULL,
  row_ann_id_col = NULL,
  columns_for_cols = c("MS_batch", "Diet", "DateTime", "order"),
  columns_for_rows = c("KEGG_pathway", "WGCNA_module", "evolutionary_distance"),
  cluster_rows = FALSE,
  cluster_cols = TRUE,
  annotation_color_cols = NULL,
  annotation_color_rows = NULL,
  fill_the_missing = -1,
  color_for_missing = "black",
  heatmap_color = colorRampPalette(rev(brewer.pal(n = 7, name = "RdYlBu")))(100),
  filename = NULL,
  width = 7,
  height = 7,
  units = c("cm", "in", "mm"),
  plot_title = NULL,
  ...
)

## S3 method for class 'ProBatchFeatures'
plot_heatmap_generic(
  data_matrix,
  pbf_name = NULL,
  column_annotation_df = NULL,
  row_annotation_df = NULL,
  col_ann_id_col = NULL,
  row_ann_id_col = NULL,
  plot_title = NULL,
  return_gridExtra = FALSE,
  plot_ncol = NULL,
  ...
)

Arguments

data_matrix

Input object: matrix-like data or a ProBatchFeatures instance.

column_annotation_df

data frame annotating columns of data_matrix

row_annotation_df

data frame annotating rows of data_matrix

col_ann_id_col

column of column_annotation_df whose values are unique identifiers of columns in data_matrix

row_ann_id_col

column of row_annotation_df whose values are unique identifiers of rows in data_matrix

columns_for_cols

vector of factors (columns) of column_annotation_df that will be mapped to color annotation of heatmap columns

columns_for_rows

vector of factors (columns) of row_annotation_df that will be mapped to color annotation of heatmap rows

cluster_rows

boolean: whether the rows should be clustered

cluster_cols

boolean: whether the columns should be clustered

annotation_color_cols

list of color vectors for column annotation, for each factor to be plotted; for factor-like variables a named vector (names should correspond to the levels of factors). Advisable to supply here color list returned by sample_annotation_to_colors

annotation_color_rows

list of color vectors for row annotation, for each factor to be plotted; for factor-like variables a named vector (names should correspond to the levels of factors). Advisable to supply here color list returned by sample_annotation_to_colors

fill_the_missing

numeric value that the missing values are substituted with, or NULL if features with missing values are to be excluded.

color_for_missing

special color to make missing values. Usually black or white, depending on heatmap_color

heatmap_color

vector of colors used in heatmap (typically a gradient)

filename

path where the results are saved. If null the object is returned to the active window; otherwise, the object is save into the file. Currently only pdf and png format is supported

width

option determining the output image width

height

option determining the output image height

units

units: 'cm', 'in' or 'mm'

plot_title

title of the plot (e.g., processing step + representation level (fragments, transitions, proteins) + purpose (meanplot/corrplot etc))

...

other parameters of link[pheatmap]{pheatmap}

pbf_name

Assay name(s) used when data_matrix is a ProBatchFeatures.

return_gridExtra

Logical; for multiple assays, return an invisible list with grob, the arranged plot, and plots, the named per-assay results.

plot_ncol

Number of columns when arranging multiple assay plots.

Value

For matrix input or one selected ProBatchFeatures assay, a pheatmap object. For multiple assays, an arranged plot is returned invisibly; with return_gridExtra = TRUE, an invisible list containing grob and the named per-assay plots is returned.

Examples

data(
    list = c("example_proteome_matrix", "example_sample_annotation"),
    package = "proBatch"
)
p <- plot_heatmap_generic(log_transform_dm(example_proteome_matrix),
    column_annotation_df = example_sample_annotation,
    columns_for_cols = c("MS_batch", "digestion_batch", "Diet", "DateTime"),
    plot_title = "test_heatmap",
    show_rownames = FALSE, show_colnames = FALSE
)

cluster the data matrix to visually inspect which confounder dominates

Description

cluster the data matrix to visually inspect which confounder dominates

Usage

## Default S3 method:
plot_hierarchical_clustering(
  data_matrix,
  sample_annotation,
  sample_id_col = "FullRunName",
  color_list = NULL,
  factors_to_plot = NULL,
  fill_the_missing = 0,
  distance = "euclidean",
  agglomeration = "complete",
  label_samples = TRUE,
  label_font = 0.2,
  filename = NULL,
  width = 38,
  height = 25,
  units = c("cm", "in", "mm"),
  plot_title = NULL,
  return_ggplot = FALSE,
  ...
)

## S3 method for class 'ProBatchFeatures'
plot_hierarchical_clustering(
  data_matrix,
  pbf_name = NULL,
  sample_annotation = NULL,
  sample_id_col = "FullRunName",
  plot_title = NULL,
  return_gridExtra = FALSE,
  plot_ncol = NULL,
  ...
)

Arguments

data_matrix

Input object: matrix-like data or a ProBatchFeatures instance.

sample_annotation

data frame with:

  1. sample_id_col (this can be repeated as row names)

  2. biological covariates

  3. technical covariates (batches etc)

. See help("example_sample_annotation")

sample_id_col

name of the column in sample_annotation table, where the filenames (colnames of the data_matrix are found).

color_list

list, as returned by sample_annotation_to_colors, where each item contains a color vector for each factor to be mapped to the color.

factors_to_plot

vector of technical and biological covariates to be plotted in this diagnostic plot (assumed to be present in sample_annotation)

fill_the_missing

numeric value determining how missing values should be substituted. If NULL, features with missing values are excluded.

distance

distance metric used for clustering

agglomeration

agglomeration methods as used by hclust

label_samples

if TRUE sample IDs (column names of data_matrix) will be printed

label_font

size of the font. Is active if label_samples is TRUE, ignored otherwise

filename

path where the results are saved. If null the object is returned to the active window; otherwise, the object is save into the file. Currently only pdf and png format is supported

width

option determining the output image width

height

option determining the output image height

units

units: 'cm', 'in' or 'mm'

plot_title

title of the plot (e.g., processing step + representation level (fragments, transitions, proteins) + purpose (meanplot/corrplot etc))

return_ggplot

logical; when TRUE, the dendrogram is returned as a ggplot object. Used internally to capture plots for multi-assay workflows. Defaults to FALSE for the default method.

...

other parameters of plotDendroAndColors from WGCNA package

pbf_name

Assay name(s) used when data_matrix is a ProBatchFeatures.

return_gridExtra

logical; when plotting multiple assays from a ProBatchFeatures object, returning TRUE provides a list with the arranged grob and individual plots (see gridExtra::arrangeGrob). Ignored by the default method.

plot_ncol

optional integer controlling the number of columns when arranging multiple assays. Ignored by the default method.

Value

For the default method, either NULL (when relying on base graphics) or a ggplot object when return_ggplot = TRUE. The ProBatchFeatures method returns a single ggplot (for one assay) or an arranged grob/ggplot collection when multiple assays are plotted; if ggplotify is unavailable, a list of per-assay results is returned invisibly.

See Also

hclust, sample_annotation_to_colors, plotDendroAndColors

Examples

# Load necessary datasets
data(
    list = c("example_proteome_matrix", "example_sample_annotation"),
    package = "proBatch"
)

selected_batches <- example_sample_annotation$MS_batch %in%
    c("Batch_1", "Batch_2")
selected_samples <- example_sample_annotation$FullRunName[selected_batches]
test_matrix <- example_proteome_matrix[, selected_samples]

# with defined color scheme:
color_list <- sample_annotation_to_colors(example_sample_annotation,
    factor_columns = c("MS_batch", "Strain", "Diet", "digestion_batch"),
    numeric_columns = c("DateTime", "order")
)
hierarchical_clustering_plot <- plot_hierarchical_clustering(
    example_proteome_matrix, example_sample_annotation,
    factors_to_plot = c("MS_batch", "Strain", "DateTime", "digestion_batch"),
    color_list = color_list, # can be NULL
    distance = "euclidean", agglomeration = "complete",
    label_samples = FALSE
)

Plot intensity density by missingness

Description

Compare the distribution of average intensities between features with and without missing observations. When 'color_by' is supplied, densities are computed within each sample group, colours distinguish groups, and linetypes distinguish 'missing_label' from 'valid_label'.

Usage

plot_NA_density(x, ...)

## Default S3 method:
plot_NA_density(
  x,
  missing_label = "Missing Value",
  valid_label = "Valid Value",
  palette = c(`Missing Value` = "#A92C23", `Valid Value` = "#345995"),
  sample_annotation = NULL,
  sample_id_col = NULL,
  color_by = NULL,
  col_vector = NULL,
  color_scheme = "brewer",
  ...
)

## S3 method for class 'ProBatchFeatures'
plot_NA_density(
  x,
  pbf_name = NULL,
  missing_label = "Missing Value",
  valid_label = "Valid Value",
  palette = c(`Missing Value` = "#A92C23", `Valid Value` = "#345995"),
  nrow = NULL,
  ncol = NULL,
  facet_scales = "free_y",
  color_by = NULL,
  sample_id_col = NULL,
  col_vector = NULL,
  color_scheme = "brewer",
  ...
)

Arguments

x

A data container. For the 'ProBatchFeatures' method this must be a 'ProBatchFeatures' object. The default method accepts any matrix-like input (including 'SummarizedExperiment').

...

Additional arguments forwarded to [ggplot2::geom_density()].

missing_label, valid_label

Labels used to distinguish rows with and without missing values.

palette

Named vector of colours mapped to 'missing_label' and 'valid_label' when 'color_by' is not supplied.

sample_annotation

Optional data frame with sample-level metadata. Row names (or the column specified via 'sample_id_col') must match the column names of the intensity matrix. When 'x' is a 'SummarizedExperiment', 'colData(x)' is used by default.

sample_id_col

Optional column in 'sample_annotation' providing unique sample identifiers. Use this when the data frame lacks row names matching the assay column names.

color_by

Optional column name or character vector of column names in 'sample_annotation' used to split grouped densities. When supplied, colours encode groups and linetypes encode 'missing_label' and 'valid_label'.

col_vector

Optional vector of colours recycled across grouped density lines defined by 'color_by'. When supplied, this compatibility argument takes precedence over 'color_scheme'.

color_scheme

Colour mapping used for grouped densities when 'color_by' is supplied. Accepts '"brewer"' (default), a named vector of colours, or a named list such as returned by [sample_annotation_to_colors()].

pbf_name

Character scalar or vector with assay names to plot. When 'NULL', the most recent assay returned by [pb_current_assay()] is used. Only used by the 'ProBatchFeatures' method.

nrow, ncol

Integers controlling the layout when multiple assays are plotted. If both are 'NULL', a roughly square layout is chosen automatically.

facet_scales

Scaling behaviour passed to [ggplot2::facet_wrap()] when multiple assays are plotted.

Value

A 'ggplot' object.

Examples

density_matrix <- matrix(
    seq_len(32),
    nrow = 8,
    dimnames = list(
        paste0("feature_", seq_len(8)),
        paste0("sample_", seq_len(4))
    )
)
density_matrix[cbind(seq_len(4), seq_len(4))] <- NA
density_plot <- plot_NA_density(density_matrix)

Plot missing-value frequency distribution

Description

Display how many features are observed in a given number of samples.

Usage

plot_NA_frequency(x, ...)

## Default S3 method:
plot_NA_frequency(x, show_percent = FALSE, fill = "#345995", ...)

## S3 method for class 'ProBatchFeatures'
plot_NA_frequency(
  x,
  pbf_name = NULL,
  fill = "#345995",
  nrow = NULL,
  ncol = NULL,
  facet_scales = "free_y",
  show_percent = FALSE,
  ...
)

Arguments

x

A data container. For the 'ProBatchFeatures' method this must be a 'ProBatchFeatures' object. The default method accepts any matrix-like input (including 'SummarizedExperiment').

...

Additional arguments are currently ignored.

show_percent

Logical; display percentages instead of raw counts.

fill

Colour used for the columns in the frequency plot.

pbf_name

Character scalar or vector with assay names to plot. When 'NULL', the most recent assay returned by [pb_current_assay()] is used. Only used by the 'ProBatchFeatures' method.

nrow, ncol

Integers controlling the layout when multiple assays are plotted. If both are 'NULL', a roughly square layout is chosen automatically.

facet_scales

Scaling behaviour for facets when plotting multiple assays.

Value

A 'ggplot' object showing the frequency distribution.

Examples

missing_matrix <- matrix(
    seq_len(24),
    nrow = 6,
    dimnames = list(
        paste0("feature_", seq_len(6)),
        paste0("sample_", seq_len(4))
    )
)
missing_matrix[cbind(seq_len(4), seq_len(4))] <- NA
frequency_plot <- plot_NA_frequency(
    missing_matrix,
    show_percent = TRUE
)

Plot missing-value heatmap(s)

Description

Functions for visualising the missingness pattern of assay intensities as a binary heatmap. The 'ProBatchFeatures' method supports drawing multiple assays at once by arranging the resulting heatmaps into a user-controlled grid layout.

Usage

plot_NA_heatmap(x, ...)

## Default S3 method:
plot_NA_heatmap(
  x,
  sample_annotation = NULL,
  sample_id_col = NULL,
  color_by = NULL,
  label_by = NULL,
  cluster_samples = TRUE,
  cluster_features = TRUE,
  show_row_dend = TRUE,
  show_column_dend = FALSE,
  missing_color = "black",
  valid_color = "grey90",
  col_vector = NULL,
  drop_complete = TRUE,
  draw = TRUE,
  main = NULL,
  ...
)

## S3 method for class 'ProBatchFeatures'
plot_NA_heatmap(
  x,
  pbf_name = NULL,
  color_by = NULL,
  label_by = NULL,
  sample_id_col = NULL,
  cluster_samples = TRUE,
  cluster_features = TRUE,
  show_row_dend = TRUE,
  show_column_dend = FALSE,
  missing_color = "black",
  valid_color = "grey90",
  col_vector = NULL,
  drop_complete = TRUE,
  nrow = NULL,
  ncol = NULL,
  draw = TRUE,
  use_subset = TRUE,
  ...
)

Arguments

x

A data container. For the 'ProBatchFeatures' method this must be a 'ProBatchFeatures' object. The default method accepts any matrix-like input (including 'SummarizedExperiment').

...

Additional parameters forwarded to [pheatmap::pheatmap()].

sample_annotation

Optional data frame with sample-level metadata. Row names (or the column specified via 'sample_id_col') must match the column names of the intensity matrix. When 'x' is a 'ProBatchFeatures' object the sample annotation defaults to 'as.data.frame(colData(x))'.

sample_id_col

Optional column in 'sample_annotation' providing unique sample identifiers. Use this when the data frame lacks row names matching the assay column names.

color_by

Optional column name or character vector of column names in 'sample_annotation' used to annotate heatmap columns. Use 'NULL' (default) or the string "No" to omit the annotation bar.

label_by

Optional column name (or character vector) used for column labels. Use 'NULL' for default assay column names or the string "No" to suppress column labels entirely.

cluster_samples, cluster_features

Logical flags controlling whether the heatmap columns/rows are clustered.

show_row_dend, show_column_dend

Logical, whether dendrograms should be drawn for the clustered rows/columns.

missing_color, valid_color

Colours used for missing ('0') and observed ('1') values respectively.

col_vector

Optional vector of colours that will be recycled to colour the unique values of 'color_by'.

drop_complete

Logical, drop features without any missing values before plotting. Defaults to 'TRUE' to focus on missingness patterns.

draw

Logical, draw the heatmap(s). Set to 'FALSE' to obtain the grob(s) without plotting. For multiple assays, the arranged grob is returned invisibly when 'draw = TRUE'.

main

Optional title passed to [pheatmap::pheatmap()] for single assays.

pbf_name

Character scalar or vector with assay names to plot. When 'NULL', the most recent assay returned by [pb_current_assay()] is used. Only used by the 'ProBatchFeatures' method.

nrow, ncol

Integers controlling the layout when multiple assays are plotted. If both are 'NULL', a roughly square layout is chosen automatically.

use_subset

Logical; randomly subset to 5000 rows/columns when assays exceed that size (only used for 'ProBatchFeatures' inputs).

Details

For a grouped view that collapses samples by metadata and shows within-group observed fractions, see [plot_grouped_NA_heatmap()].

Value

For a single assay the returned value is the 'pheatmap' object. When multiple assays are requested a list is returned invisibly with elements 'grob' (the arranged heatmaps) and 'heatmaps' (individual 'pheatmap' objects). Assays without missing values are skipped with a warning.

Examples

missing_matrix <- matrix(
    seq_len(24),
    nrow = 6,
    dimnames = list(
        paste0("feature_", seq_len(6)),
        paste0("sample_", seq_len(4))
    )
)
missing_matrix[cbind(seq_len(4), seq_len(4))] <- NA
na_heatmap <- plot_NA_heatmap(
    missing_matrix,
    cluster_samples = FALSE,
    cluster_features = FALSE,
    draw = FALSE
)

Plot missingness versus mean intensity per feature

Description

For each feature (row), compute the mean observed intensity and the proportion of missing values, optionally stratified by a sample-level grouping variable. A scatter plot with a spline-smoothed trend and per-group Spearman correlations is returned. The x-axis label assumes that the input intensities are log2 transformed; callers using another scale can relabel the returned plot.

Usage

plot_NA_intensity(x, ...)

## Default S3 method:
plot_NA_intensity(
  x,
  sample_annotation = NULL,
  sample_id_col = NULL,
  color_by = NULL,
  color_scheme = "brewer",
  col_vector = NULL,
  spline_df = 3L,
  point_alpha = 0.15,
  point_size = 0.6,
  ...
)

## S3 method for class 'ProBatchFeatures'
plot_NA_intensity(
  x,
  pbf_name = NULL,
  color_by = NULL,
  sample_id_col = NULL,
  color_scheme = "brewer",
  col_vector = NULL,
  spline_df = 3L,
  point_alpha = 0.15,
  point_size = 0.6,
  nrow = NULL,
  ncol = NULL,
  facet_scales = "free_y",
  ...
)

Arguments

x

A data container. For the 'ProBatchFeatures' method this must be a 'ProBatchFeatures' object. The default method accepts any matrix-like input (including 'SummarizedExperiment').

...

Currently unused.

sample_annotation

Optional data frame with sample-level metadata. Row names (or the column specified via 'sample_id_col') must match the column names of the intensity matrix. When 'x' is a 'SummarizedExperiment', 'colData(x)' is used by default.

sample_id_col

Optional column in 'sample_annotation' providing unique sample identifiers.

color_by

Column name in 'sample_annotation' used to stratify features into sample groups. When 'NULL', all samples are treated as a single group.

color_scheme

Colour mapping for groups. Accepts '"brewer"' (default), a named vector of colours, or a named list such as returned by [sample_annotation_to_colors()].

col_vector

Optional vector of colours recycled across groups defined by 'color_by'.

spline_df

Degrees of freedom for the natural spline fitted via [stats::glm()] with a quasi-binomial family. Set to '0' to suppress the trend line.

point_alpha, point_size

Transparency and size of individual points.

pbf_name

Character scalar or vector with assay names to plot. When 'NULL', the most recent assay returned by [pb_current_assay()] is used. Only used by the 'ProBatchFeatures' method.

nrow, ncol

Integers controlling the layout when multiple assays are plotted.

facet_scales

Scaling behaviour passed to [ggplot2::facet_wrap()] when multiple assays are plotted.

Value

A 'ggplot' object.

Examples

data(example_proteome_matrix, package = "proBatch")
data(example_sample_annotation, package = "proBatch")
example_matrix <- example_proteome_matrix[1:100, ]
intensity_plot <- plot_NA_intensity(
    example_matrix,
    sample_annotation = example_sample_annotation,
    sample_id_col = "FullRunName",
    color_by = "Diet"
)
pbf <- ProBatchFeatures(
    data_matrix = example_matrix,
    sample_annotation = example_sample_annotation,
    sample_id_col = "FullRunName"
)
pbf_intensity_plot <- plot_NA_intensity(pbf, color_by = "Diet")

plot PCA plot

Description

plot PCA plot

Usage

## Default S3 method:
plot_PCA(
  data_matrix,
  sample_annotation,
  feature_id_col = "peptide_group_label",
  sample_id_col = "FullRunName",
  color_by = "MS_batch",
  shape_by = NULL,
  PC_to_plot = c(1, 2),
  fill_the_missing = -1,
  color_scheme = "brewer",
  filename = NULL,
  width = NA,
  height = NA,
  units = c("cm", "in", "mm"),
  plot_title = NULL,
  theme_name = "classic",
  base_size = 10,
  point_size = 3,
  point_alpha = 0.8,
  marginal_density = FALSE,
  x_nPC = NULL,
  y_nPC = NULL,
  ...
)

## S3 method for class 'ProBatchFeatures'
plot_PCA(
  data_matrix,
  pbf_name = NULL,
  sample_annotation = NULL,
  sample_id_col = "FullRunName",
  plot_title = NULL,
  return_gridExtra = FALSE,
  plot_ncol = NULL,
  ...
)

Arguments

data_matrix

Numeric feature-by-sample matrix or a ProBatchFeatures object.

sample_annotation

data frame with:

  1. sample_id_col (this can be repeated as row names)

  2. biological covariates

  3. technical covariates (batches etc)

. See help("example_sample_annotation")

feature_id_col

name of the column with feature/gene/peptide/protein ID used in the long format representation df_long. In the wide formatted representation data_matrix this corresponds to the row names.

sample_id_col

name of the column in sample_annotation table, where the filenames (colnames of the data_matrix are found).

color_by

Column name in sample_annotation to color by. Factor-like and numeric columns are supported.

shape_by

Optional factor-like annotation column used for point shapes.

PC_to_plot

Integer vector of length 2 giving the PC indices for x and y axes.

fill_the_missing

Missing-value handling shared by PCA, t-SNE, and UMAP. A finite numeric scalar replaces missing values and defaults to -1; NULL or FALSE removes incomplete features. The function warns before applying either non-error handling path.

color_scheme

a named vector of colors to map to batch_col, names corresponding to the levels of the factor. For continuous variables, vector doesn't need to be named.

filename

path where the results are saved. If null the object is returned to the active window; otherwise, the object is save into the file. Currently only pdf and png format is supported

width

option determining the output image width

height

option determining the output image height

units

units: 'cm', 'in' or 'mm'

plot_title

title of the plot (e.g., processing step + representation level (fragments, transitions, proteins) + purpose (meanplot/corrplot etc))

theme_name

Plot theme name. Only "classic" is currently implemented; use NULL for the default ggplot theme.

base_size

base size of the text in the plot

point_size

Point size supplied to ggplot2::geom_point().

point_alpha

Alpha transparency for plotted points.

marginal_density

Logical or a single column name. If TRUE, add marginal density plots grouped by color_by. If a column name is provided, densities are grouped by that column. Numeric-like grouping columns fall back to pooled marginals.

x_nPC

Optional integer PC index for the x axis. Use together with y_nPC to override PC_to_plot.

y_nPC

Optional integer PC index for the y axis. Use together with x_nPC to override PC_to_plot.

...

For ProBatchFeatures input, additional arguments forwarded to plot_PCA.default(). The default method rejects unused arguments.

pbf_name

Assay name(s) used when data_matrix is a ProBatchFeatures.

return_gridExtra

Logical; for multiple assays, return an invisible list containing the arranged grob and named ordered plots.

plot_ncol

Number of columns when arranging multiple assay plots.

Value

A ggplot PCA scatterplot colored by the column specified in color_by. Factor-like values, including numeric values matched by a named palette, use a discrete scale; other numeric values use a continuous gradient. When marginal_density = TRUE, returns a ggplot object if ggplotify or cowplot is available; otherwise returns a grid grob. For one selected ProBatchFeatures assay, returns that plot. For multiple assays, returns an invisible arranged plot; with return_gridExtra = TRUE, returns an invisible list containing the arranged grob and named ordered plots.

See Also

autoplot.pca_common, ggplot

Examples

data(
    list = c("example_proteome_matrix", "example_sample_annotation"),
    package = "proBatch"
)
matrix_test <- na.omit(example_proteome_matrix)[1:50, ]
pca_plot <- plot_PCA(matrix_test, example_sample_annotation,
    color_by = "MS_batch", plot_title = "PCA colored by MS batch"
)
pca_plot <- plot_PCA(matrix_test, example_sample_annotation,
    color_by = "DateTime", plot_title = "PCA colored by DateTime"
)
pca_plot <- plot_PCA(matrix_test, example_sample_annotation,
    color_by = "MS_batch", marginal_density = TRUE
)
pca_plot <- plot_PCA(matrix_test, example_sample_annotation,
    color_by = "MS_batch", marginal_density = "digestion_batch"
)

color_list <- sample_annotation_to_colors(example_sample_annotation,
    factor_columns = c("MS_batch", "digestion_batch"),
    numeric_columns = c("DateTime", "order")
)
pca_plot <- plot_PCA(matrix_test, example_sample_annotation,
    color_by = "DateTime", color_scheme = color_list[["DateTime"]]
)

pca_plot <- plot_PCA(matrix_test, example_sample_annotation,
    color_by = "MS_batch", x_nPC = 2, y_nPC = 3,
    plot_title = "PCA (PC2 vs PC3)"
)

pca_file <- tempfile("pca_plot", fileext = ".png")
pca_plot <- plot_PCA(matrix_test, example_sample_annotation,
    color_by = "DateTime", plot_title = "PCA colored by DateTime",
    filename = pca_file, width = 14, height = 9, units = "cm"
)
unlink(pca_file)

Create violin plot of peptide correlation distribution

Description

Plot distribution of peptide correlations within one protein and between proteins

Usage

plot_peptide_corr_distribution(
  data_matrix,
  peptide_annotation,
  protein_col = "ProteinName",
  feature_id_col = "peptide_group_label",
  filename = NULL,
  width = NA,
  height = NA,
  units = c("cm", "in", "mm"),
  plot_title = "Distribution of peptide correlation",
  theme = "classic",
  pbf_name = NULL
)

plot_peptide_corr_distribution.corrDF(
  corr_distribution,
  filename = NULL,
  width = NA,
  height = NA,
  units = c("cm", "in", "mm"),
  plot_title = "Correlation of peptides",
  theme = "classic",
  base_size = 20
)

Arguments

data_matrix

features (in rows) vs samples (in columns) matrix, with feature IDs in rownames and file/sample names as colnames, or a 'ProBatchFeatures' object. When 'data_matrix' is a 'ProBatchFeatures' object, 'pbf_name' is used (or the current assay when 'pbf_name = NULL').

peptide_annotation

long format data frame with peptide ID and their corresponding protein and/or gene annotations. When 'data_matrix' is a matrix, this argument is required. When 'data_matrix' is a 'ProBatchFeatures' object and 'peptide_annotation' is not provided, rowData from the selected assay is used.

protein_col

column where protein names are specified

feature_id_col

name of the column with feature/gene/peptide/protein ID used in the long format representation df_long. In the wide formatted representation data_matrix this corresponds to the row names.

filename

path where the results are saved. If null the object is returned to the active window; otherwise, the object is save into the file. Currently only pdf and png format is supported

width

option determining the output image width

height

option determining the output image height

units

units: 'cm', 'in' or 'mm'

plot_title

title of the plot (e.g., processing step + representation level (fragments, transitions, proteins) + purpose (meanplot/corrplot etc))

theme

ggplot theme, by default classic. Can be easily overridden

pbf_name

Assay name used when 'data_matrix' is a 'ProBatchFeatures' object. If 'NULL', [pb_current_assay()] is used.

corr_distribution

data frame with peptide correlation distribution

base_size

base font size

Value

ggplot object (violin plot of peptide correlation)

See Also

calculate_peptide_corr_distr, ggplot

Examples

data(
    list = c("example_peptide_annotation", "example_proteome_matrix"),
    package = "proBatch"
)
peptide_corr_distribution <- plot_peptide_corr_distribution(
    example_proteome_matrix,
    example_peptide_annotation,
    protein_col = "Gene"
)

data(
    list = c("example_peptide_annotation", "example_proteome_matrix"),
    package = "proBatch"
)
corr_distribution <- calculate_peptide_corr_distr(
    example_proteome_matrix,
    example_peptide_annotation,
    protein_col = "Gene"
)
peptide_corr_distribution <-
    plot_peptide_corr_distribution.corrDF(corr_distribution)

Peptide correlation matrix (heatmap)

Description

Plots correlation plot of peptides from a single protein

Usage

plot_protein_corrplot(
  data_matrix,
  protein_name,
  peptide_annotation = NULL,
  protein_col = "ProteinName",
  feature_id_col = "peptide_group_label",
  factors_to_plot = c("ProteinName"),
  cluster_rows = FALSE,
  cluster_cols = FALSE,
  heatmap_color = colorRampPalette(rev(brewer.pal(n = 7, name = "RdYlBu")))(100),
  color_list = NULL,
  filename = NULL,
  width = NA,
  height = NA,
  units = c("cm", "in", "mm"),
  plot_title = NULL,
  ...
)

Arguments

data_matrix

features (in rows) vs samples (in columns) matrix, with feature IDs in rownames and file/sample names as colnames. See "example_proteome_matrix" for more details (to call the description, use help("example_proteome_matrix"))

protein_name

the name of the protein

peptide_annotation

long format data frame with peptide ID and their corresponding protein and/or gene annotations. See help("example_peptide_annotation").

protein_col

column where protein names are specified

feature_id_col

name of the column with feature/gene/peptide/protein ID used in the long format representation df_long. In the wide formatted representation data_matrix this corresponds to the row names.

factors_to_plot

vector of technical and biological covariates to be plotted in this diagnostic plot (assumed to be present in sample_annotation)

cluster_rows

logical; whether rows should be clustered.

cluster_cols

logical; whether columns should be clustered.

heatmap_color

vector of colors used in heatmap.

color_list

list, as returned by sample_annotation_to_colors, where each item contains a color vector for each factor to be mapped to the color.

filename

path where the results are saved. If null the object is returned to the active window; otherwise, the object is save into the file. Currently only pdf and png format is supported

width

option determining the output image width

height

option determining the output image height

units

units: 'cm', 'in' or 'mm'

plot_title

title of the plot (e.g., processing step + representation level (fragments, transitions, proteins) + purpose (meanplot/corrplot etc))

...

parameters for the corrplot visualisation

Value

pheatmap object

Examples

data(
    list = c("example_peptide_annotation", "example_proteome_matrix"),
    package = "proBatch"
)
protein_corrplot_plot <- plot_protein_corrplot(example_proteome_matrix,
    protein_name = "Haao", peptide_annotation = example_peptide_annotation,
    protein_col = "Gene"
)

Plot variance distribution by variable

Description

Plot variance distribution by variable

Usage

## Default S3 method:
plot_PVCA(
  data_matrix,
  sample_annotation,
  feature_id_col = "peptide_group_label",
  sample_id_col = "FullRunName",
  technical_factors = c("MS_batch", "instrument"),
  biological_factors = c("cell_line", "drug_dose"),
  fill_the_missing = -1,
  pca_threshold = 0.6,
  variance_threshold = 0.01,
  colors_for_bars = NULL,
  filename = NULL,
  width = NA,
  height = NA,
  units = c("cm", "in", "mm"),
  plot_title = NULL,
  theme = "classic",
  base_size = 15,
  path_to_save_results = NULL,
  ...
)

## S3 method for class 'ProBatchFeatures'
plot_PVCA(
  data_matrix,
  pbf_name = NULL,
  sample_annotation = NULL,
  feature_id_col = "peptide_group_label",
  sample_id_col = "FullRunName",
  plot_title = NULL,
  return_gridExtra = FALSE,
  plot_ncol = NULL,
  stacked_bar = FALSE,
  stacked_plot_title = "Plot of weighted average proportion variance vs effects in PVCA",
  sort_stacked = NULL,
  category_order = NULL,
  path_to_save_results = NULL,
  ...
)

Arguments

data_matrix

Input object: matrix-like data or a ProBatchFeatures instance.

sample_annotation

data frame with:

  1. sample_id_col (this can be repeated as row names)

  2. biological covariates

  3. technical covariates (batches etc)

. See help("example_sample_annotation")

feature_id_col

name of the column with feature/gene/peptide/protein ID used in the long format representation df_long. In the wide formatted representation data_matrix this corresponds to the row names.

sample_id_col

name of the column in sample_annotation table, where the filenames (colnames of the data_matrix are found).

technical_factors

vector sample_annotation column names that are technical covariates

biological_factors

vector sample_annotation column names, that are biologically meaningful covariates

fill_the_missing

numeric value determining how missing values should be substituted. If NULL, features with missing values are excluded. If NULL, features with missing values are excluded.

pca_threshold

the percentile value of the minimum amount of the variabilities that the selected principal components need to explain

variance_threshold

the percentile value of weight each of the covariates needs to explain (the rest will be lumped together)

colors_for_bars

four-item color vector, specifying colors for the following categories: c('residual', 'biological', 'biol:techn', 'technical')

filename

path where the results are saved. If null the object is returned to the active window; otherwise, the object is save into the file. Currently only pdf and png format is supported

width

option determining the output image width

height

option determining the output image height

units

units: 'cm', 'in' or 'mm'

plot_title

title of the plot (e.g., processing step + representation level (fragments, transitions, proteins) + purpose (meanplot/corrplot etc))

theme

ggplot theme, by default classic. Can be easily overridden

base_size

base size of the text in the plot

path_to_save_results

optional directory where aggregated PVCA results are written as CSV.

...

Additional arguments passed to lower-level methods. The default method accepts add_values = TRUE to annotate bars with rounded weights.

pbf_name

Assay name(s) used when data_matrix is a ProBatchFeatures.

return_gridExtra

Logical; for multiple assays, return an invisible list with grob, the arranged plot, and plots, the named per-assay results.

plot_ncol

Number of columns when arranging multiple assay plots.

stacked_bar

logical; when TRUE and multiple pbf_name values are provided, combines all assays in a single stacked bar chart (supported for ProBatchFeatures inputs only).

stacked_plot_title

optional character vector that annotates the stacked PVCA plot when stacked_bar = TRUE; elements are joined with newlines.

sort_stacked

optional factor name used to order stacked bars when stacked_bar = TRUE; assays are ordered by the explained variance of this factor in descending order.

category_order

optional character vector specifying the category order in a stacked PVCA plot.

Value

For matrix/data-frame input or one selected assay, a ggplot object. For multiple ProBatchFeatures assays, stacked_bar = TRUE returns one stacked ggplot; otherwise an arranged plot is returned invisibly. With return_gridExtra = TRUE, an invisible list containing grob and the named per-assay plots is returned.

See Also

sample_annotation_to_colors, ggplot

Examples

data(
    list = c("example_proteome_matrix", "example_sample_annotation"),
    package = "proBatch"
)
matrix_test <- na.omit(example_proteome_matrix)[1:50, ]

pvca_file <- tempfile("pvca", fileext = ".png")
pvca_plot <- plot_PVCA(
    matrix_test,
    example_sample_annotation,
    technical_factors = c("MS_batch", "digestion_batch"),
    biological_factors = c("Diet", "Sex", "Strain"),
    filename = pvca_file, # save to file, can be NULL
    width = 12, height = 8, units = "cm"
)
unlink(pvca_file)

Plot stacked PVCA results from saved CSV files

Description

When PVCA analysis has been run previously and the aggregated weights were written to disk (one PVCA_results_aggregated.csv per assay), this helper rebuilds the stacked bar summary without rerunning the analysis.

Usage

plot_PVCA_stacked_from_saved(
  pvca_dir,
  sort_stacked = NULL,
  colors_for_bars = NULL,
  plot_title = NULL,
  stacked_plot_title = "Plot of weighted average proportion variance vs effects in PVCA",
  theme = "classic",
  base_size = 15,
  filename = NULL,
  width = NA,
  height = NA,
  units = c("cm", "in", "mm"),
  category_order = NULL
)

Arguments

pvca_dir

Directory that contains per-assay PVCA_results_aggregated.csv files (the function searches recursively).

sort_stacked

Optional factor label used to order the rows of the stacked plot (matching sort_stacked in plot_PVCA.ProBatchFeatures).

colors_for_bars

Character vector of four colors (residual, biological, biol:techn, technical) passed to the stacked bar helper.

plot_title

Fallback plot title used when stacked_plot_title = NULL.

stacked_plot_title

Optional character vector used as the stacked plot title; elements are joined with newline characters. Its non-NULL default takes precedence over plot_title.

theme

Plot theme; only "classic" is currently implemented.

base_size

Base font size passed to theme_classic().

filename

Optional path to save the stacked plot.

width

Plot width forwarded to ggplot2::ggsave().

height

Plot height forwarded to ggplot2::ggsave().

units

Plot units forwarded to ggplot2::ggsave().

category_order

Optional character vector specifying the order of categories in the stacked plot.

Value

A ggplot object showing the stacked PVCA weights.

Examples

pvca_dir <- tempfile("saved_pvca_")
pvca_plot <- tryCatch({
    assay_dir <- file.path(pvca_dir, "assay_1")
    dir.create(assay_dir, recursive = TRUE)
    saved_pvca <- data.frame(
        label = c("Diet", "resid"),
        weights = c(0.7, 0.3),
        category = c("biological", "residual")
    )
    utils::write.csv(
        saved_pvca,
        file.path(assay_dir, "PVCA_results_aggregated.csv"),
        row.names = FALSE
    )
    plot_PVCA_stacked_from_saved(pvca_dir)
}, finally = {
    unlink(pvca_dir, recursive = TRUE)
})

plot PVCA, when the analysis is completed

Description

plot PVCA, when the analysis is completed

Usage

## S3 method for class 'df'
plot_PVCA(
  data_matrix,
  pbf_name = NULL,
  sample_annotation = NULL,
  feature_id_col = "peptide_group_label",
  sample_id_col = "FullRunName",
  colors_for_bars = NULL,
  filename = NULL,
  width = NA,
  height = NA,
  units = c("cm", "in", "mm"),
  plot_title = NULL,
  theme = "classic",
  base_size = 15,
  return_gridExtra = FALSE,
  plot_ncol = NULL,
  ...
)

Arguments

data_matrix

Data frame of PVCA weights, typically the result of prepare_PVCA_df(), or a ProBatchFeatures object.

pbf_name

Assay name(s) used when data_matrix is a ProBatchFeatures.

sample_annotation

data frame with:

  1. sample_id_col (this can be repeated as row names)

  2. biological covariates

  3. technical covariates (batches etc)

. See help("example_sample_annotation")

feature_id_col

name of the column with feature/gene/peptide/protein ID used in the long format representation df_long. In the wide formatted representation data_matrix this corresponds to the row names.

sample_id_col

name of the column in sample_annotation table, where the filenames (colnames of the data_matrix) are found.

colors_for_bars

four-item color vector, specifying colors for the following categories: c('residual', 'biological', 'biol:techn', 'technical')

filename

path where the results are saved. If null the object is returned to the active window; otherwise, the object is save into the file. Currently only pdf and png format is supported

width

option determining the output image width

height

option determining the output image height

units

units: 'cm', 'in' or 'mm'

plot_title

title of the plot (e.g., processing step + representation level (fragments, transitions, proteins) + purpose (meanplot/corrplot etc))

theme

ggplot theme, by default classic. Can be easily overridden

base_size

base size of the text in the plot

return_gridExtra

Logical; for multiple assays, return an invisible list with grob, the arranged plot, and plots, the named per-assay results.

plot_ncol

Number of columns when arranging multiple assay plots.

...

Additional arguments. For a ProBatchFeatures input, stacked_bar, stacked_plot_title, sort_stacked, and category_order control multi-assay presentation; remaining computation arguments, including path_to_save_results, are forwarded to prepare_PVCA_df(). For all inputs, add_values = TRUE annotates bars with rounded weights.

Details

plot_PVCA.df() is retained as a directly callable compatibility helper and registered for the historical "df" S3 class. Prepared PVCA data frames can continue to call the helper directly.

Value

For data-frame input or one selected assay, a ggplot object. For multiple ProBatchFeatures assays, stacked_bar = TRUE returns one stacked ggplot; otherwise an arranged plot is returned invisibly. With return_gridExtra = TRUE, an invisible list containing grob and the named per-assay plots is returned.

Examples

data(
    list = c("example_proteome_matrix", "example_sample_annotation"),
    package = "proBatch"
)
matrix_test <- na.omit(example_proteome_matrix)[1:50, ]
pvca_df_res <- prepare_PVCA_df(matrix_test, example_sample_annotation,
    technical_factors = c("MS_batch", "digestion_batch"),
    biological_factors = c("Diet", "Sex", "Strain"),
    pca_threshold = .6, variance_threshold = .01, fill_the_missing = -1
)
colors_for_bars <- c("grey", "green", "blue", "red")
names(colors_for_bars) <- c(
    "residual", "biological", "biol:techn", "technical"
)

pvca_plot <- plot_PVCA.df(
    pvca_df_res,
    colors_for_bars = colors_for_bars
)

Create violin plot of sample correlation distribution

Description

Useful to visualize within batch vs within replicate vs non-related sample correlation

Usage

plot_sample_corr_distribution(
  data_matrix,
  sample_annotation,
  repeated_samples = NULL,
  sample_id_col = "FullRunName",
  batch_col = "MS_batch",
  biospecimen_id_col = "EarTag",
  filename = NULL,
  width = NA,
  height = NA,
  units = c("cm", "in", "mm"),
  plot_title = "Sample correlation distribution",
  plot_param = "batch_replicate",
  theme = "classic",
  pbf_name = NULL
)

plot_sample_corr_distribution.corrDF(
  corr_distribution,
  filename = NULL,
  width = NA,
  height = NA,
  units = c("cm", "in", "mm"),
  plot_title = "Sample correlation distribution",
  plot_param = "batch_replicate",
  theme = "classic",
  base_size = 20
)

Arguments

data_matrix

features (in rows) vs samples (in columns) matrix, with feature IDs in rownames and file/sample names as colnames, or a 'ProBatchFeatures' object. When 'data_matrix' is a 'ProBatchFeatures' object, 'pbf_name' is used (or the current assay when 'pbf_name = NULL').

sample_annotation

data frame with sample-level metadata. When 'data_matrix' is a matrix, this argument is required. When 'data_matrix' is a 'ProBatchFeatures' object and 'sample_annotation' is not provided, 'as.data.frame(colData(data_matrix))' is used.

repeated_samples

if NULL, correlation of all samples is plotted

sample_id_col

name of the column in sample_annotation table, where the filenames (colnames of the data_matrix are found).

batch_col

column in sample_annotation that should be used for batch comparison (or other, non-batch factor to be mapped to color in plots).

biospecimen_id_col

column in sample_annotation that captures the biological sample, that (possibly) was profiled several times as technical replicates. Tip: if such ID is absent, but can be defined from several columns, create new biospecimen_id column

filename

path where the results are saved. If null the object is returned to the active window; otherwise, the object is save into the file. Currently only pdf and png format is supported

width

option determining the output image width

height

option determining the output image height

units

units: 'cm', 'in' or 'mm'

plot_title

title of the plot (e.g., processing step + representation level (fragments, transitions, proteins) + purpose (meanplot/corrplot etc))

plot_param

columns, defined in correlation_df, which is output of calculate_sample_corr_distr, specifically,

  1. replicate

  2. batch_the_same

  3. batch_replicate

  4. batches

theme

ggplot theme, by default classic. Can be easily overridden

pbf_name

Assay name used when 'data_matrix' is a 'ProBatchFeatures' object. If 'NULL', [pb_current_assay()] is used.

corr_distribution

data frame with correlation distribution, as returned by calculate_sample_corr_distr

base_size

base font size

Value

ggplot type object with violin plot for each plot_param

See Also

calculate_sample_corr_distr, ggplot

Examples

data(
    list = c("example_sample_annotation", "example_proteome_matrix"),
    package = "proBatch"
)
sample_corr_distribution_plot <- plot_sample_corr_distribution(
    example_proteome_matrix,
    example_sample_annotation,
    batch_col = "MS_batch",
    biospecimen_id_col = "EarTag",
    plot_param = "batch_replicate"
)

data(
    list = c("example_sample_annotation", "example_proteome_matrix"),
    package = "proBatch"
)
corr_distribution <- calculate_sample_corr_distr(
    data_matrix = example_proteome_matrix,
    sample_annotation = example_sample_annotation,
    batch_col = "MS_batch", biospecimen_id_col = "EarTag"
)
sample_corr_distribution_plot <- plot_sample_corr_distribution.corrDF(
    corr_distribution,
    plot_param = "batch_replicate"
)

Sample correlation matrix (heatmap)

Description

Plot correlation of selected samples

Usage

plot_sample_corr_heatmap(
  data_matrix,
  samples_to_plot = NULL,
  sample_annotation = NULL,
  sample_id_col = "FullRunName",
  factors_to_plot = NULL,
  cluster_rows = FALSE,
  cluster_cols = FALSE,
  show_row_dend = TRUE,
  show_column_dend = TRUE,
  x_axis_label_size = NULL,
  y_axis_label_size = NULL,
  heatmap_color = colorRampPalette(rev(brewer.pal(n = 7, name = "RdYlBu")))(100),
  color_list = NULL,
  filename = NULL,
  width = NA,
  height = NA,
  units = c("cm", "in", "mm"),
  plot_title = sprintf("Correlation matrix of%s samples",
    ifelse(is.null(samples_to_plot), "", " selected")),
  pbf_name = NULL,
  plot_ncol = NULL,
  ...
)

Arguments

data_matrix

features (in rows) vs samples (in columns) matrix, with feature IDs in rownames and file/sample names as colnames, or a 'ProBatchFeatures' object. When 'data_matrix' is a 'ProBatchFeatures' object, 'pbf_name' is used (or all assays when 'pbf_name = NULL').

samples_to_plot

string vector of samples in data_matrix to be used in the plot

sample_annotation

optional data frame with sample-level metadata. Supply it for matrix input when annotation tracks are requested. For 'ProBatchFeatures' input, omitted annotation defaults to 'as.data.frame(colData(data_matrix))'.

sample_id_col

name of the column in sample_annotation table, where the filenames (colnames of the data_matrix are found).

factors_to_plot

vector of technical and biological covariates to be plotted in this diagnostic plot (assumed to be present in sample_annotation)

cluster_rows

logical; whether rows should be clustered.

cluster_cols

logical; whether columns should be clustered.

show_row_dend, show_column_dend

Logical, whether row/column dendrograms should be shown when clustering is enabled.

x_axis_label_size, y_axis_label_size

Optional numeric font sizes for x-axis (column) and y-axis (row) labels in the heatmap.

heatmap_color

vector of colors used in heatmap.

color_list

list, as returned by sample_annotation_to_colors, where each item contains a color vector for each factor to be mapped to the color.

filename

path where the results are saved. If null the object is returned to the active window; otherwise, the object is save into the file. Currently only pdf and png format is supported

width

option determining the output image width

height

option determining the output image height

units

units: 'cm', 'in' or 'mm'

plot_title

title of the plot (e.g., processing step + representation level (fragments, transitions, proteins) + purpose (meanplot/corrplot etc))

pbf_name

Assay name(s) used when 'data_matrix' is a 'ProBatchFeatures' object. If 'NULL', all assays are plotted.

plot_ncol

Number of columns when arranging multiple assay plots.

...

parameters for the pheatmap visualisation, for details see examples and help to corresponding functions

Value

pheatmap object for a single assay, or an arranged plot object when multiple assays are plotted.

See Also

pheatmap

Examples

data(
    list = c("example_sample_annotation", "example_proteome_matrix"),
    package = "proBatch"
)
specified_samples <- example_sample_annotation$FullRunName[
    which(example_sample_annotation$order %in% 110:115)
]

sample_corr_heatmap <- plot_sample_corr_heatmap(example_proteome_matrix,
    samples_to_plot = specified_samples,
    sample_annotation = example_sample_annotation,
    factors_to_plot = c("MS_batch", "Diet", "DateTime", "digestion_batch"),
    cluster_rows = FALSE, cluster_cols = FALSE,
    annotation_names_col = TRUE, annotation_legend = FALSE,
    show_colnames = FALSE
)

Plot per-sample mean or boxplots for initial assessment

Description

Plot per-sample means or boxplots showing medians and quantiles. For ordered samples, such as consecutive mass-spectrometry runs, the plots show order-associated effects.

Usage

## Default S3 method:
plot_sample_mean(
  x,
  sample_annotation,
  sample_id_col = "FullRunName",
  batch_col = "MS_batch",
  color_by_batch = FALSE,
  color_scheme = "brewer",
  order_col = "order",
  vline_color = "grey",
  facet_col = NULL,
  filename = NULL,
  width = NA,
  height = NA,
  units = c("cm", "in", "mm"),
  plot_title = NULL,
  theme_name = c("classic", "minimal", "bw", "light", "dark"),
  base_size = 20,
  ylimits = NULL,
  pbf_name = NULL,
  ...
)

## Default S3 method:
plot_boxplot(
  x,
  sample_annotation,
  sample_id_col = "FullRunName",
  measure_col = "Intensity",
  batch_col = "MS_batch",
  color_by_batch = TRUE,
  color_scheme = "brewer",
  order_col = "order",
  facet_col = NULL,
  filename = NULL,
  width = NA,
  height = NA,
  units = c("cm", "in", "mm"),
  plot_title = NULL,
  theme_name = c("classic", "minimal", "bw", "light", "dark"),
  base_size = 20,
  ylimits = NULL,
  outliers = TRUE,
  pbf_name = NULL,
  ...
)

## S3 method for class 'ProBatchFeatures'
plot_sample_mean(x, pbf_name = NULL, plot_title = NULL, ...)

## S3 method for class 'ProBatchFeatures'
plot_boxplot(
  x,
  pbf_name = NULL,
  sample_id_col = NULL,
  plot_title = NULL,
  plot_ncol = NULL,
  return_gridExtra = FALSE,
  ...
)

plot_sample_mean(x, ...)

plot_boxplot(x, ...)

Arguments

x

Input supplied to the generics: a matrix, long data frame, or 'ProBatchFeatures' object.

sample_annotation

data frame with:

  1. sample_id_col (this can be repeated as row names)

  2. biological covariates

  3. technical covariates (batches etc)

. See help("example_sample_annotation")

sample_id_col

name of the column in sample_annotation table, where the filenames (colnames of the data_matrix are found).

batch_col

column in sample_annotation that should be used for batch comparison (or other, non-batch factor to be mapped to color in plots).

color_by_batch

(logical) whether to color points and connecting lines by batch factor as defined by batch_col.

color_scheme

Either '"brewer"' for an inferred palette or a named vector whose names correspond to unique values of 'batch_col' in 'sample_annotation'. A suitable mapping can be created with [sample_annotation_to_colors()].

order_col

column in sample_annotation that determines sample order. It is used for in initial assessment plots (plot_sample_mean_or_boxplot) and feature-level diagnostics (feature_level_diagnostics). Can be 'NULL' if sample order is irrelevant (e.g. in genomic experiments). For more details, order definition/inference, see define_sample_order and date_to_sample_order

vline_color

Color of vertical lines that typically denote different MS batches in ordered runs. Use 'NULL' for experiments without an intrinsic order.

facet_col

column in sample_annotation with a batch factor to separate plots into facets; usually 2nd to batch_col. Most meaningful for multi-instrument MS experiments (where each instrument has its own order-associated effects (see order_col) or simultaneous examination of two batch factors (e.g. preparation day and measurement day). For single-instrument case should be set to 'NULL'

filename

path where the results are saved. If null the object is returned to the active window; otherwise, the object is save into the file. Currently only pdf and png format is supported

width

option determining the output image width

height

option determining the output image height

units

units: 'cm', 'in' or 'mm'

plot_title

title of the plot (e.g., processing step + representation level (fragments, transitions, proteins) + purpose (meanplot/corrplot etc))

theme_name

Name of the ggplot theme to apply to the resulting plot.

base_size

base font size

ylimits

Optional y-axis range for comparing plots side by side.

pbf_name

Assay name used by 'plot_sample_mean()' or one or more assay names used by 'plot_boxplot()' when 'x' is a 'ProBatchFeatures' object.

...

Additional arguments forwarded between methods.

measure_col

if df_long is among the parameters, it is the column with expression/abundance/intensity; otherwise, it is used internally for consistency.

outliers

Logical; keep boxplot outliers when 'TRUE' (the default) or hide them when 'FALSE'.

plot_ncol

Number of columns when arranging multiple assay plots.

return_gridExtra

Logical; for multiple boxplots, return an invisible list containing the arranged 'grob' and named per-assay 'plots'.

Value

For matrix/data-frame input or one selected assay, a 'ggplot' object. Multiple 'ProBatchFeatures' boxplots return an arranged plot invisibly; with 'return_gridExtra = TRUE', an invisible list containing the arranged 'grob' and named per-assay 'plots' is returned.

See Also

[ggplot2::ggplot()], [date_to_sample_order()]

Examples

data(
    list = c("example_proteome", "example_sample_annotation"),
    package = "proBatch"
)
keep <- !duplicated(example_sample_annotation$MS_batch) |
    !duplicated(example_sample_annotation$MS_batch, fromLast = TRUE)
annotation_small <- example_sample_annotation[keep, ]
annotation_small$order <- seq_len(nrow(annotation_small))
proteome_small <- subset(
    example_proteome, FullRunName %in% annotation_small$FullRunName)
plot_boxplot(
    proteome_small,
    sample_annotation = annotation_small,
    batch_col = "MS_batch"
)

Plot split violin plot (convenient to compare distribution before and after)

Description

Plot split violin plot (convenient to compare distribution before and after)

Usage

plot_split_violin_with_boxplot(
  df,
  y_col = "y",
  col_for_color = "m",
  col_for_box = "x",
  colors_for_plot = c("#8f1811", "#F8C333"),
  hlineintercept = NULL,
  plot_title = NULL,
  theme = "classic"
)

Arguments

df

data.frame with y_col, col_for_color, col_for_box

y_col

value to explore the distribution of

col_for_color

column to use to map to two colors

col_for_box

column to use to do group comparison

colors_for_plot

colors to map to col_for_color

hlineintercept

NULL: no intercept line; non-null: intercept value ...

plot_title

title of the plot (e.g., processing step + representation level (fragments, transitions, proteins) + purpose (meanplot/corrplot etc))

theme

ggplot theme, by default classic. Can be easily overridden

Value

ggplot object

Examples

df <- data.frame(
    x = rep(c("A", "B"), each = 100), y = rnorm(200),
    m = rep(c("C", "D"), 100)
)
plot_split_violin_with_boxplot(
    df,
    y_col = "y", col_for_color = "m", col_for_box = "x"
)

Plot a t-SNE embedding of samples

Description

Compute t-SNE with samples as observations (matrix columns) and return a static ggplot by default. Interactive Plotly rendering is optional.

Usage

## Default S3 method:
plot_TSNE(
  data_matrix,
  sample_annotation,
  feature_id_col = "peptide_group_label",
  sample_id_col = "FullRunName",
  color_by = "MS_batch",
  shape_by = NULL,
  tsne_dims = 2,
  perplexity = 30,
  initial_dims = 50,
  max_iter = 1000,
  fill_the_missing = -1,
  color_scheme = "brewer",
  plot_title = NULL,
  point_size = 3,
  point_alpha = 0.85,
  random_seed = NULL,
  use_plotlyrender = FALSE,
  theme_name = "classic",
  base_size = 10,
  plotly_param = list(width = 800, height = 600),
  ...
)

## S3 method for class 'ProBatchFeatures'
plot_TSNE(
  data_matrix,
  pbf_name = NULL,
  sample_annotation = NULL,
  sample_id_col = "FullRunName",
  plot_title = NULL,
  use_plotlyrender = FALSE,
  assay_args = NULL,
  return_gridExtra = FALSE,
  plot_ncol = NULL,
  return_subplots = FALSE,
  subplot_ncol = NULL,
  share_axes = TRUE,
  ...
)

plot_TSNE(data_matrix, ...)

Arguments

data_matrix

Numeric feature-by-sample matrix or a ProBatchFeatures object.

sample_annotation

data frame with:

  1. sample_id_col (this can be repeated as row names)

  2. biological covariates

  3. technical covariates (batches etc)

. See help("example_sample_annotation")

feature_id_col

name of the column with feature/gene/peptide/protein ID used in the long format representation df_long. In the wide formatted representation data_matrix this corresponds to the row names.

sample_id_col

name of the column in sample_annotation table, where the filenames (colnames of the data_matrix are found).

color_by

Column name in sample_annotation to color by. Factor-like and numeric columns are supported.

shape_by

Optional factor-like annotation column used for point shapes.

tsne_dims

Integer number of embedding dimensions, at least two. The first two dimensions are plotted.

perplexity

Positive t-SNE perplexity. Values above max(1, floor((n_samples - 1) / 3)) are reduced with a warning.

initial_dims

Positive integer number of input dimensions retained by the initial PCA step performed by the backend.

max_iter

Positive integer number of t-SNE iterations.

fill_the_missing

Missing-value handling shared by PCA, t-SNE, and UMAP. A finite numeric scalar replaces missing values and defaults to -1; NULL or FALSE removes incomplete features. The function warns before applying either non-error handling path.

color_scheme

a named vector of colors to map to batch_col, names corresponding to the levels of the factor. For continuous variables, vector doesn't need to be named.

plot_title

title of the plot (e.g., processing step + representation level (fragments, transitions, proteins) + purpose (meanplot/corrplot etc))

point_size

Point size supplied to ggplot2::geom_point().

point_alpha

Alpha transparency for plotted points.

random_seed

Optional integer seed for reproducible t-SNE coordinates. A supplied seed is scoped to the backend call and leaves the caller's random-number state unchanged. When NULL, the caller controls that state.

use_plotlyrender

Logical; return a plotly object instead of a ggplot.

theme_name

Plot theme name. Only "classic" is currently implemented; use NULL for the default ggplot theme.

base_size

base size of the text in the plot

plotly_param

Named list of optional arguments such as width and height passed to plotly::plot_ly().

...

Named backend arguments forwarded to Rtsne::Rtsne() by the default method. In the ProBatchFeatures method these are shared default-method arguments.

pbf_name

Assay name(s) used when data_matrix is a ProBatchFeatures.

assay_args

ProBatchFeatures method only. A named list keyed by selected assay, with each value a named list that overrides shared default-method arguments for that assay.

return_gridExtra

Logical; for multiple assays, return an invisible list containing the arranged grob and named ordered plots.

plot_ncol

Number of columns when arranging multiple assay plots.

return_subplots

Logical; combine multiple interactive assay plots with plotly::subplot().

subplot_ncol

Optional positive integer number of subplot columns.

share_axes

One logical value shared by both axes, or two logical values for the x and y axes.

Details

Each input assay must contain at least two samples.

Value

For matrix input, a ggplot or, when requested, a plotly object. Plot data follow the sample order in the input matrix columns. For one selected ProBatchFeatures assay, the corresponding single plot. For multiple assays, an arranged static result, a named ordered list of interactive plots, or an explicitly requested Plotly subplot.

Examples

sample_ids <- paste0("sample_", seq_len(8))
feature_ids <- paste0("feature_", seq_len(12))
embedding_matrix <- matrix(
    seq_len(96) + sin(seq_len(96)),
    nrow = 12,
    dimnames = list(feature_ids, sample_ids)
)
embedding_annotation <- data.frame(
    FullRunName = sample_ids,
    MS_batch = rep(c("batch_1", "batch_2"), each = 4)
)
if (requireNamespace("Rtsne", quietly = TRUE)) {
    tsne_plot <- plot_TSNE(
        embedding_matrix,
        embedding_annotation,
        perplexity = 2,
        max_iter = 250,
        random_seed = 7
    )
}

Plot a UMAP embedding of samples

Description

Compute UMAP with samples as observations (matrix columns) and return a static ggplot by default. Interactive Plotly rendering is optional.

Usage

## Default S3 method:
plot_UMAP(
  data_matrix,
  sample_annotation,
  feature_id_col = "peptide_group_label",
  sample_id_col = "FullRunName",
  color_by = "MS_batch",
  shape_by = NULL,
  n_neighbors = 15,
  min_dist = 0.1,
  metric = "euclidean",
  n_components = 2,
  fill_the_missing = -1,
  color_scheme = "brewer",
  plot_title = NULL,
  point_size = 3,
  point_alpha = 0.85,
  random_state = NULL,
  spread = NULL,
  learning_rate = NULL,
  use_plotlyrender = FALSE,
  theme_name = "classic",
  base_size = 10,
  plotly_param = list(width = 800, height = 600),
  ...
)

## S3 method for class 'ProBatchFeatures'
plot_UMAP(
  data_matrix,
  pbf_name = NULL,
  sample_annotation = NULL,
  sample_id_col = "FullRunName",
  plot_title = NULL,
  use_plotlyrender = FALSE,
  assay_args = NULL,
  return_gridExtra = FALSE,
  plot_ncol = NULL,
  return_subplots = FALSE,
  subplot_ncol = NULL,
  share_axes = TRUE,
  ...
)

plot_UMAP(data_matrix, ...)

Arguments

data_matrix

Numeric feature-by-sample matrix or a ProBatchFeatures object.

sample_annotation

data frame with:

  1. sample_id_col (this can be repeated as row names)

  2. biological covariates

  3. technical covariates (batches etc)

. See help("example_sample_annotation")

feature_id_col

name of the column with feature/gene/peptide/protein ID used in the long format representation df_long. In the wide formatted representation data_matrix this corresponds to the row names.

sample_id_col

name of the column in sample_annotation table, where the filenames (colnames of the data_matrix are found).

color_by

Column name in sample_annotation to color by. Factor-like and numeric columns are supported.

shape_by

Optional factor-like annotation column used for point shapes.

n_neighbors

Integer number of neighbours used to construct the local UMAP graph; must be at least two and, for inputs with three or more samples, smaller than the sample count.

min_dist

Non-negative minimum distance between embedded points.

metric

Single distance-metric name understood by umap::umap().

n_components

Integer embedding dimensionality of at least two. The first two dimensions are plotted.

fill_the_missing

Missing-value handling shared by PCA, t-SNE, and UMAP. A finite numeric scalar replaces missing values and defaults to -1; NULL or FALSE removes incomplete features. The function warns before applying either non-error handling path.

color_scheme

a named vector of colors to map to batch_col, names corresponding to the levels of the factor. For continuous variables, vector doesn't need to be named.

plot_title

title of the plot (e.g., processing step + representation level (fragments, transitions, proteins) + purpose (meanplot/corrplot etc))

point_size

Point size supplied to ggplot2::geom_point().

point_alpha

Alpha transparency for plotted points.

random_state

Optional integer placed in the UMAP configuration for reproducible coordinates. When NULL, the caller controls randomness.

spread

Optional positive numeric UMAP spread.

learning_rate

Optional positive numeric UMAP learning rate, forwarded as the backend configuration's alpha value.

use_plotlyrender

Logical; return a plotly object instead of a ggplot.

theme_name

Plot theme name. Only "classic" is currently implemented; use NULL for the default ggplot theme.

base_size

base size of the text in the plot

plotly_param

Named list of optional arguments such as width and height passed to plotly::plot_ly().

...

Named backend arguments forwarded to umap::umap() by the default method. In the ProBatchFeatures method these are shared default-method arguments.

pbf_name

Assay name(s) used when data_matrix is a ProBatchFeatures.

assay_args

ProBatchFeatures method only. A named list keyed by selected assay, with each value a named list that overrides shared default-method arguments for that assay.

return_gridExtra

Logical; for multiple assays, return an invisible list containing the arranged grob and named ordered plots.

plot_ncol

Number of columns when arranging multiple assay plots.

return_subplots

Logical; combine multiple interactive assay plots with plotly::subplot().

subplot_ncol

Optional positive integer number of subplot columns.

share_axes

One logical value shared by both axes, or two logical values for the x and y axes.

Details

Each input assay must contain at least two samples.

Value

For matrix input, a ggplot or, when requested, a plotly object. Multi-assay return behavior matches plot_TSNE().

Examples

sample_ids <- paste0("sample_", seq_len(8))
feature_ids <- paste0("feature_", seq_len(12))
embedding_matrix <- matrix(
    cos(seq_len(96)) + seq_len(96) / 100,
    nrow = 12,
    dimnames = list(feature_ids, sample_ids)
)
embedding_annotation <- data.frame(
    FullRunName = sample_ids,
    MS_batch = rep(c("batch_1", "batch_2"), each = 4)
)
if (requireNamespace("umap", quietly = TRUE)) {
    umap_plot <- plot_UMAP(
        embedding_matrix,
        embedding_annotation,
        n_neighbors = 3,
        random_state = 7
    )
}

prepare the weights of Principal Variance Components

Description

prepare the weights of Principal Variance Components

Usage

## Default S3 method:
prepare_PVCA_df(
  data_matrix,
  sample_annotation,
  feature_id_col = "peptide_group_label",
  sample_id_col = "FullRunName",
  technical_factors = c("MS_batch", "instrument"),
  biological_factors = c("cell_line", "drug_dose"),
  fill_the_missing = -1,
  pca_threshold = 0.6,
  variance_threshold = 0.01,
  path_to_save_results = NULL,
  ...
)

## S3 method for class 'ProBatchFeatures'
prepare_PVCA_df(
  data_matrix,
  pbf_name = NULL,
  sample_annotation = NULL,
  feature_id_col = "peptide_group_label",
  sample_id_col = "FullRunName",
  ...
)

Arguments

data_matrix

features (in rows) vs samples (in columns) matrix, with feature IDs in rownames and file/sample names as colnames. See "example_proteome_matrix" for more details (to call the description, use help("example_proteome_matrix"))

sample_annotation

data frame with:

  1. sample_id_col (this can be repeated as row names)

  2. biological covariates

  3. technical covariates (batches etc)

. See help("example_sample_annotation")

feature_id_col

name of the column with feature/gene/peptide/protein ID used in the long format representation df_long. In the wide formatted representation data_matrix this corresponds to the row names.

sample_id_col

name of the column in sample_annotation table, where the filenames (colnames of the data_matrix are found).

technical_factors

vector sample_annotation column names that are technical covariates

biological_factors

vector sample_annotation column names, that are biologically meaningful covariates

fill_the_missing

numeric value determining how missing values should be substituted. If NULL, features with missing values are excluded. If NULL, features with missing values are excluded.

pca_threshold

the percentile value of the minimum amount of the variabilities that the selected principal components need to explain

variance_threshold

the percentile value of weight each of the covariates needs to explain (the rest will be lumped together)

path_to_save_results

optional directory where aggregated PVCA results are written as PVCA_results_aggregated.csv.

...

Additional arguments forwarded between methods.

pbf_name

Assay name(s) used when data_matrix is a ProBatchFeatures.

Value

For matrix input, a plotting-ready data frame containing weights, labels, and factor categories. For ProBatchFeatures input, one selected assay returns that data frame and multiple assays return a named list of data frames.

Examples

data(
    list = c("example_proteome_matrix", "example_sample_annotation"),
    package = "proBatch"
)
matrix_test <- na.omit(example_proteome_matrix)[1:50, ]

pvca_df_res <- prepare_PVCA_df(matrix_test, example_sample_annotation,
    technical_factors = c("MS_batch", "digestion_batch"),
    biological_factors = c("Diet", "Sex", "Strain"),
    pca_threshold = .6, variance_threshold = .01, fill_the_missing = -1
)

proBatch: A package for diagnostics and correction of batch effects, primarily in proteomics

Description

The proBatch package contains functions for analyzing and correcting batch effects (unwanted technical variation) from high-throughput experiments. Although the package has primarily been developed for mass spectrometry proteomics (DIA/SWATH), it has been designed be applicable to most omic data with minor adaptations. It addresses the following needs:

  • prepare the data for analysis

  • Visualize batch effects in sample-wide and feature-level;

  • Normalize and correct for batch effects.

Arguments

df_long

data frame where each row is a single feature in a single sample. It minimally has a sample_id_col, a feature_id_col and a measure_col, but usually also an m_score (in OpenSWATH output result file). See help("example_proteome") for more details.

data_matrix

features (in rows) vs samples (in columns) matrix, with feature IDs in rownames and file/sample names as colnames. See "example_proteome_matrix" for more details (to call the description, use help("example_proteome_matrix"))

sample_annotation

data frame with:

  1. sample_id_col (this can be repeated as row names)

  2. biological covariates

  3. technical covariates (batches etc)

. See help("example_sample_annotation")

sample_id_col

name of the column in sample_annotation table, where the filenames (colnames of the data_matrix are found).

measure_col

if df_long is among the parameters, it is the column with expression/abundance/intensity; otherwise, it is used internally for consistency.

feature_id_col

name of the column with feature/gene/peptide/protein ID used in the long format representation df_long. In the wide formatted representation data_matrix this corresponds to the row names.

batch_col

column in sample_annotation that should be used for batch comparison (or other, non-batch factor to be mapped to color in plots).

order_col

column in sample_annotation that determines sample order. It is used for in initial assessment plots (plot_sample_mean_or_boxplot) and feature-level diagnostics (feature_level_diagnostics). Can be 'NULL' if sample order is irrelevant (e.g. in genomic experiments). For more details, order definition/inference, see define_sample_order and date_to_sample_order

facet_col

column in sample_annotation with a batch factor to separate plots into facets; usually 2nd to batch_col. Most meaningful for multi-instrument MS experiments (where each instrument has its own order-associated effects (see order_col) or simultaneous examination of two batch factors (e.g. preparation day and measurement day). For single-instrument case should be set to 'NULL'

color_by_batch

(logical) whether to color points and connecting lines by batch factor as defined by batch_col.

peptide_annotation

long format data frame with peptide ID and their corresponding protein and/or gene annotations. See help("example_peptide_annotation").

color_scheme

a named vector of colors to map to batch_col, names corresponding to the levels of the factor. For continuous variables, vector doesn't need to be named.

color_list

list, as returned by sample_annotation_to_colors, where each item contains a color vector for each factor to be mapped to the color.

factors_to_plot

vector of technical and biological covariates to be plotted in this diagnostic plot (assumed to be present in sample_annotation)

protein_col

column where protein names are specified

no_fit_imputed

(logical) whether to use imputed (requant) values, as flagged in qual_col by qual_value for data transformation

qual_col

column to color point by certain value denoted by qual_value. Design with inferred/requant values in OpenSWATH output data, which means argument value has to be set to m_score.

qual_value

value in qual_col to color. For OpenSWATH data, this argument value has to be set to 2 (this is an m_score value for imputed values (requant values).

plot_title

title of the plot (e.g., processing step + representation level (fragments, transitions, proteins) + purpose (meanplot/corrplot etc))

keep_all

when transforming the data (normalize, correct) - acceptable values: all/default/minimal (which set of columns be kept).

theme

ggplot theme, by default classic. Can be easily overridden

filename

path where the results are saved. If null the object is returned to the active window; otherwise, the object is save into the file. Currently only pdf and png format is supported

width

option determining the output image width

height

option determining the output image height

units

units: 'cm', 'in' or 'mm'

base_size

base font size

Details

To learn more about proBatch, start with the vignettes: browseVignettes(package = "proBatch")

Value

No return value.

Section

Common arguments to the functions.

Author(s)

Maintainer: Yuliya Burankova [email protected]

Authors:

See Also

Useful links:

Examples

if (interactive()) {
    browseVignettes(package = "proBatch")
}

Construct a ProBatchFeatures object from a wide matrix + sample annotation.

Description

Construct a ProBatchFeatures object from a wide matrix + sample annotation.

Usage

ProBatchFeatures(
  data_matrix,
  sample_annotation = NULL,
  sample_id_col = "FullRunName",
  name = NULL,
  level = "feature"
)

Arguments

data_matrix

numeric matrix (features x samples)

sample_annotation

Optional data frame with sample metadata (rows = samples). When NULL, the object uses empty sample metadata.

sample_id_col

Character scalar naming the column in sample_annotation that matches colnames(data_matrix). Set it to NULL or "" to use row names instead.

name

Optional non-missing, non-empty character scalar. A pipeline shorthand is combined with level; a full name must use ⁠<level>::<pipeline>⁠. If missing, the name is ⁠<level>::raw⁠.

level

character label like "peptide"/"protein" (default "feature").

Value

A ProBatchFeatures object.

Examples

# Shared setup for ProBatchFeatures documentation examples -----------------
data("example_ecoli_data", package = "proBatch")

# Extract data
all_metadata <- example_ecoli_data$all_metadata
all_precursors <- example_ecoli_data$all_precursors
all_protein_groups <- example_ecoli_data$all_protein_groups
all_precursor_pg_match <- example_ecoli_data$all_precursor_pg_match

# Keep only essential
rm(example_ecoli_data)

# Construct a ProBatchFeatures object --------------------------------------
pbf <- ProBatchFeatures(
    data_matrix = all_precursors,
    sample_annotation = all_metadata,
    sample_id_col = "Run",
    level = "peptide"
)

# Register a custom step and evaluate it -----------------------------------
example_step <- "example_add_one"
if (!pb_has_step(example_step)) {
    pb_register_step(example_step, function(x) x + 1)
}
head(pb_eval(pbf, from = "peptide::raw", steps = example_step))

# Derived objects for downstream helpers -----------------------------------
pbf_logged <- pb_transform(
    pbf,
    from = "peptide::raw",
    steps = c("log2", "medianNorm"),
    store_fast_steps = TRUE
)

# Get information about the object ---------------------------------------
get_operation_log(pbf_logged)
get_chain(pbf_logged)
get_chain(pbf_logged, as_string = TRUE)
pb_pipeline_name(pbf_logged) # the latest pipeline
pb_pipeline_name(pbf_logged, assay = "peptide::raw")

# Access assays and matrices ------------------------------------------------
head(pb_current_assay(pbf_logged)) # the latest assay
head(pb_assay_matrix(pbf_logged)) # the latest matrix
head(pb_assay_matrix(pbf_logged, assay = "peptide::raw")) # the latest matrix
head(pb_as_wide(pbf_logged)) # the latest assay in wide format
head(pb_as_long(pbf_logged, sample_id_col = "Run")) # the latest assay in long format

# Pipeline evaluation without storing --------------------------------------
head(pb_eval(
    pbf,
    from = "peptide::raw",
    steps = c("log2", "medianNorm")
))

# Long-format constructor ---------------------------------------------------
long_pbf <- pb_as_long(pbf_logged, sample_id_col = "Run") # the latest assay in long format

ProBatchFeatures_from_long(
    df_long = long_pbf,
    sample_annotation = all_metadata,
    sample_id_col = "Run",
    feature_id_col = "feature_label",
    level = "peptide"
)


# Add proteins as a new level and link via mapping
#    all_precursor_pg_match has columns: "Precursor.Id", "Protein.Ids"
pbf <- pb_add_level(
    object = pbf,
    from = "peptide::raw",
    new_matrix = all_protein_groups,
    to_level = "protein", # will name "protein::raw" by default
    mapping_df = all_precursor_pg_match,
    from_id = "Precursor.Id",
    to_id = "Protein.Ids",
    map_strategy = "as_is"
)

# Aggregate and add levels --------------------------------------------------
pb_aggregate_level(
    pbf,
    from = "peptide::raw",
    feature_var = "ProteinID",
    new_level = "protein_new"
)

Construct from LONG df via proBatch::long_to_matrix

Description

Construct from LONG df via proBatch::long_to_matrix

Usage

ProBatchFeatures_from_long(
  df_long,
  sample_annotation = NULL,
  feature_id_col = "peptide_group_label",
  sample_id_col = "FullRunName",
  measure_col = "Intensity",
  level = "feature",
  name = NULL
)

Arguments

df_long

Data frame in long format with feature/sample/value columns.

sample_annotation

Optional sample metadata aligned to the samples.

feature_id_col

Column containing feature identifiers in df_long.

sample_id_col

Column containing sample identifiers in df_long.

measure_col

Column with the measured intensity values.

level

Character label describing the biological level of the assay.

name

Optional non-missing, non-empty pipeline or full assay name; defaults to ⁠<level>::raw⁠ when missing.

Value

A ProBatchFeatures object constructed from the long-format input.

Examples

# Shared setup for ProBatchFeatures documentation examples -----------------
data("example_ecoli_data", package = "proBatch")

# Extract data
all_metadata <- example_ecoli_data$all_metadata
all_precursors <- example_ecoli_data$all_precursors
all_protein_groups <- example_ecoli_data$all_protein_groups
all_precursor_pg_match <- example_ecoli_data$all_precursor_pg_match

# Keep only essential
rm(example_ecoli_data)

# Construct a ProBatchFeatures object --------------------------------------
pbf <- ProBatchFeatures(
    data_matrix = all_precursors,
    sample_annotation = all_metadata,
    sample_id_col = "Run",
    level = "peptide"
)

# Register a custom step and evaluate it -----------------------------------
example_step <- "example_add_one"
if (!pb_has_step(example_step)) {
    pb_register_step(example_step, function(x) x + 1)
}
head(pb_eval(pbf, from = "peptide::raw", steps = example_step))

# Derived objects for downstream helpers -----------------------------------
pbf_logged <- pb_transform(
    pbf,
    from = "peptide::raw",
    steps = c("log2", "medianNorm"),
    store_fast_steps = TRUE
)

# Get information about the object ---------------------------------------
get_operation_log(pbf_logged)
get_chain(pbf_logged)
get_chain(pbf_logged, as_string = TRUE)
pb_pipeline_name(pbf_logged) # the latest pipeline
pb_pipeline_name(pbf_logged, assay = "peptide::raw")

# Access assays and matrices ------------------------------------------------
head(pb_current_assay(pbf_logged)) # the latest assay
head(pb_assay_matrix(pbf_logged)) # the latest matrix
head(pb_assay_matrix(pbf_logged, assay = "peptide::raw")) # the latest matrix
head(pb_as_wide(pbf_logged)) # the latest assay in wide format
head(pb_as_long(pbf_logged, sample_id_col = "Run")) # the latest assay in long format

# Pipeline evaluation without storing --------------------------------------
head(pb_eval(
    pbf,
    from = "peptide::raw",
    steps = c("log2", "medianNorm")
))

# Long-format constructor ---------------------------------------------------
long_pbf <- pb_as_long(pbf_logged, sample_id_col = "Run") # the latest assay in long format

ProBatchFeatures_from_long(
    df_long = long_pbf,
    sample_annotation = all_metadata,
    sample_id_col = "Run",
    feature_id_col = "feature_label",
    level = "peptide"
)


# Add proteins as a new level and link via mapping
#    all_precursor_pg_match has columns: "Precursor.Id", "Protein.Ids"
pbf <- pb_add_level(
    object = pbf,
    from = "peptide::raw",
    new_matrix = all_protein_groups,
    to_level = "protein", # will name "protein::raw" by default
    mapping_df = all_precursor_pg_match,
    from_id = "Precursor.Id",
    to_id = "Protein.Ids",
    map_strategy = "as_is"
)

# Aggregate and add levels --------------------------------------------------
pb_aggregate_level(
    pbf,
    from = "peptide::raw",
    feature_var = "ProteinID",
    new_level = "protein_new"
)

ProBatchFeatures: QFeatures subclass with operation log, levels/pipelines, and lazy storage

Description

Assay naming convention: "<level>::<pipeline>" e.g., "peptide::raw", "protein::median_on_log" Pipelines are strings produced by get_chain(as_string=TRUE), e.g., "combat_on_medianNorm_on_log".

Details

Ephemeral "fast" steps are computed but not stored by default (store_fast_steps = FALSE). Use pb_eval() to compute and return data after a step/pipeline without storing. Use pb_transform() to build pipelines and optionally materialize the final assay.

Value

No return value; defines the ProBatchFeatures S4 class.

Slots

chain

character() ordered list of steps (e.g., c("log","medianNorm","combat")).

oplog

S4Vectors::DataFrame with columns: - step (character), fun (character), from (character), to (character), params (list), timestamp (POSIXct), pkg (character)

Examples

# Shared setup for ProBatchFeatures documentation examples -----------------
data("example_ecoli_data", package = "proBatch")

# Extract data
all_metadata <- example_ecoli_data$all_metadata
all_precursors <- example_ecoli_data$all_precursors
all_protein_groups <- example_ecoli_data$all_protein_groups
all_precursor_pg_match <- example_ecoli_data$all_precursor_pg_match

# Keep only essential
rm(example_ecoli_data)

# Construct a ProBatchFeatures object --------------------------------------
pbf <- ProBatchFeatures(
    data_matrix = all_precursors,
    sample_annotation = all_metadata,
    sample_id_col = "Run",
    level = "peptide"
)

# Register a custom step and evaluate it -----------------------------------
example_step <- "example_add_one"
if (!pb_has_step(example_step)) {
    pb_register_step(example_step, function(x) x + 1)
}
head(pb_eval(pbf, from = "peptide::raw", steps = example_step))

# Derived objects for downstream helpers -----------------------------------
pbf_logged <- pb_transform(
    pbf,
    from = "peptide::raw",
    steps = c("log2", "medianNorm"),
    store_fast_steps = TRUE
)

# Get information about the object ---------------------------------------
get_operation_log(pbf_logged)
get_chain(pbf_logged)
get_chain(pbf_logged, as_string = TRUE)
pb_pipeline_name(pbf_logged) # the latest pipeline
pb_pipeline_name(pbf_logged, assay = "peptide::raw")

# Access assays and matrices ------------------------------------------------
head(pb_current_assay(pbf_logged)) # the latest assay
head(pb_assay_matrix(pbf_logged)) # the latest matrix
head(pb_assay_matrix(pbf_logged, assay = "peptide::raw")) # the latest matrix
head(pb_as_wide(pbf_logged)) # the latest assay in wide format
head(pb_as_long(pbf_logged, sample_id_col = "Run")) # the latest assay in long format

# Pipeline evaluation without storing --------------------------------------
head(pb_eval(
    pbf,
    from = "peptide::raw",
    steps = c("log2", "medianNorm")
))

# Long-format constructor ---------------------------------------------------
long_pbf <- pb_as_long(pbf_logged, sample_id_col = "Run") # the latest assay in long format

ProBatchFeatures_from_long(
    df_long = long_pbf,
    sample_annotation = all_metadata,
    sample_id_col = "Run",
    feature_id_col = "feature_label",
    level = "peptide"
)


# Add proteins as a new level and link via mapping
#    all_precursor_pg_match has columns: "Precursor.Id", "Protein.Ids"
pbf <- pb_add_level(
    object = pbf,
    from = "peptide::raw",
    new_matrix = all_protein_groups,
    to_level = "protein", # will name "protein::raw" by default
    mapping_df = all_precursor_pg_match,
    from_id = "Precursor.Id",
    to_id = "Protein.Ids",
    map_strategy = "as_is"
)

# Aggregate and add levels --------------------------------------------------
pb_aggregate_level(
    pbf,
    from = "peptide::raw",
    feature_var = "ProteinID",
    new_level = "protein_new"
)

Generate colors for sample annotation

Description

Convert the sample annotation data frame to list of colors the list is named as columns included to use in plotting functions

Usage

## Default S3 method:
sample_annotation_to_colors(
  sample_annotation,
  sample_id_col = "FullRunName",
  factor_columns = NULL,
  numeric_columns = NULL,
  rare_categories_to_other = TRUE,
  guess_factors = FALSE,
  numeric_palette_type = "brewer",
  ...
)

## S3 method for class 'ProBatchFeatures'
sample_annotation_to_colors(sample_annotation, ...)

sample_annotation_to_colors(sample_annotation, ...)

Arguments

sample_annotation

Input object supplied to the generic (data frame or 'ProBatchFeatures').

sample_id_col

name of the column in sample_annotation table, where the filenames (colnames of the data_matrix are found).

factor_columns

columns of sample_annotation to be treated as factors. Sometimes categorical variables are depicted as integers (e.g. in column "Batch", values are 1, 2 and 3), specification here allows to map them correctly to qualitative palettes.

numeric_columns

columns of sample_annotation to be treated as continuous numeric values.

rare_categories_to_other

if True rare categories will be merged into the value "other"

guess_factors

whether attempt which of the factor_columns are actually numeric

numeric_palette_type

palette to be used for numeric values coloring (can be 'brewer' and 'viridis')

...

Additional arguments forwarded to method implementations.

Value

list of colors for the selected annotation columns. Use color_list_to_df if a data frame representation is needed.

Examples

data("example_sample_annotation", package = "proBatch")
color_scheme <- sample_annotation_to_colors(
    example_sample_annotation,
    factor_columns = c(
        "MS_batch", "EarTag", "Strain",
        "Diet", "digestion_batch", "Sex"
    ),
    numeric_columns = c("DateTime", "order")
)

Detect sub-batches within batches

Description

Detect sub-batches within batches

Usage

subbatch_detection(
  data_matrix,
  sample_annotation,
  batch_col,
  n_pcs = 10,
  method = c("hclust", "kmeans"),
  k_max = 6,
  pbf_name = NULL
)

Arguments

data_matrix

features (in rows) vs samples (in columns) matrix, with feature IDs in rownames and file/sample names as colnames. See "example_proteome_matrix" for more details (to call the description, use help("example_proteome_matrix"))

sample_annotation

data frame with:

  1. sample_id_col (this can be repeated as row names)

  2. biological covariates

  3. technical covariates (batches etc)

. See help("example_sample_annotation")

batch_col

column in sample_annotation that should be used for batch comparison (or other, non-batch factor to be mapped to color in plots).

n_pcs

number of principal components to use.

method

clustering method; "hclust" or "kmeans".

k_max

maximum number of clusters to evaluate per batch.

pbf_name

Assay name used when 'data_matrix' is a 'ProBatchFeatures' object. If 'NULL', [pb_current_assay()] is used.

Value

A list with per-sample assignments, per-batch summaries, and suggestions. The object has class "pb_subbatches".

Examples

data("example_ecoli_data", package = "proBatch")
meta <- example_ecoli_data$all_metadata
dm <- as.matrix(example_ecoli_data$all_protein_groups)[1:200, ]
subbatches <- subbatch_detection(
    dm,
    sample_annotation = meta,
    batch_col = "Lab",
    n_pcs = 5,
    method = "kmeans",
    k_max = 4
)

Summarise design matrix structure

Description

Summarise design matrix structure

Usage

summarize_design(
  sample_annotation,
  batch_col,
  condition_col = NULL,
  covariates = NULL,
  add_intercept = TRUE
)

Arguments

sample_annotation

data frame with:

  1. sample_id_col (this can be repeated as row names)

  2. biological covariates

  3. technical covariates (batches etc)

. See help("example_sample_annotation")

batch_col

column in sample_annotation that should be used for batch comparison (or other, non-batch factor to be mapped to color in plots).

condition_col

optional column in sample_annotation indicating the primary biological condition.

covariates

optional character vector of additional covariate columns.

add_intercept

logical; include intercept in the design matrix.

Value

A list with design diagnostics: design_matrix_dim, rank, deficiency, kappa, aliased_terms, flagged_covariates, and notes. The object has class "pb_design_summary".

Examples

data("example_ecoli_data", package = "proBatch")
meta <- example_ecoli_data$all_metadata
summarize_design(
    meta,
    batch_col = "Lab",
    condition_col = "Condition",
    add_intercept = TRUE
)

Functions to log transform raw data before normalization and batch correction

Description

Functions to log transform raw data before normalization and batch correction

Log transformation of the data long format.

"Unlog" transformation of the data to pre-log form (for quantification, forcing log-transform)

Log transformation of the data matrix format.

Usage

log_transform_df(df_long, log_base = 2, offset = 1, measure_col = "Intensity")

unlog_df(df_long, log_base = 2, offset = 1, measure_col = "Intensity")

log_transform_dm(x, ...)

## Default S3 method:
log_transform_dm(x, log_base = 2, offset = 1, ...)

## S3 method for class 'ProBatchFeatures'
log_transform_dm(
  x,
  log_base = 2,
  offset = 1,
  pbf_name = NULL,
  final_name = NULL,
  ...
)

unlog_dm(x, ...)

## Default S3 method:
unlog_dm(x, log_base = 2, offset = 1, ...)

## S3 method for class 'ProBatchFeatures'
unlog_dm(x, log_base = 2, offset = 1, pbf_name = NULL, final_name = NULL, ...)

Arguments

df_long

data frame where each row is a single feature in a single sample. It minimally has a sample_id_col, a feature_id_col and a measure_col, but usually also an m_score (in OpenSWATH output result file). See help("example_proteome") for more details.

log_base

base of the logarithm for transformation

offset

small positive number to prevent 0 conversion to -Inf

measure_col

if df_long is among the parameters, it is the column with expression/abundance/intensity; otherwise, it is used internally for consistency.

x

Input object supplied to the generics (long data frame, matrix, or 'ProBatchFeatures').

...

For 'log_transform_dm.ProBatchFeatures()', additional arguments forwarded to [pb_transform()]. The default matrix methods and 'unlog_dm.ProBatchFeatures()' currently ignore additional arguments.

pbf_name

Assay name to transform when 'x' is a 'ProBatchFeatures'.

final_name

Optional name for the stored assay produced by the S3 methods.

Value

'log_transform_df()' returns a data frame with 'measure_col' log-transformed and the original values stored in 'beforeLog_<measure_col>'. 'unlog_df()' returns a data frame with 'measure_col' restored to its pre-log scale and the prior values stored in 'beforeUnLog_<measure_col>'. When 'log_base = NULL', these functions return the input unchanged. The default matrix methods return the transformed matrix. The 'ProBatchFeatures' methods return the transformed 'ProBatchFeatures' result produced by [pb_transform()].

Examples

data(
    list = c("example_proteome", "example_proteome_matrix"),
    package = "proBatch"
)

log_transformed_df <- log_transform_df(example_proteome)

log_transformed_matrix <- log_transform_dm(example_proteome_matrix,
    log_base = 10, offset = 1
)

Validate batch/design annotations

Description

Validate batch/design annotations

Usage

validate_batch_design(
  sample_annotation,
  batch_col,
  condition_col = NULL,
  covariates = NULL,
  sample_id_col = NULL,
  strict = TRUE
)

Arguments

sample_annotation

data frame with:

  1. sample_id_col (this can be repeated as row names)

  2. biological covariates

  3. technical covariates (batches etc)

. See help("example_sample_annotation")

batch_col

column in sample_annotation that should be used for batch comparison (or other, non-batch factor to be mapped to color in plots).

condition_col

optional column in sample_annotation indicating the primary biological condition.

covariates

optional character vector of additional covariate columns.

sample_id_col

name of the column in sample_annotation table, where the filenames (colnames of the data_matrix are found).

strict

logical; when TRUE, stop on validation errors.

Value

A list with errors, warnings, and summary. The object has class "pb_design_check".

Examples

data("example_ecoli_data", package = "proBatch")
meta <- example_ecoli_data$all_metadata
validate_batch_design(
    meta,
    batch_col = "Lab",
    condition_col = "Condition",
    sample_id_col = "Run",
    strict = FALSE
)

Warn about unmapped columns

Description

Emit a warning if some columns will not be mapped to colors.

Usage

warn_unmapped_columns(
  sample_annotation,
  columns_for_color_mapping,
  sample_id_col
)

Arguments

sample_annotation

data frame containing sample annotations.

columns_for_color_mapping

character vector of columns to be mapped.

sample_id_col

character, the ID column.

Value

No return value, called for side effects (warning).

Examples

annotation <- data.frame(
    sample = c("s1", "s2"),
    batch = c("A", "B"),
    injection_order = 1:2
)
tryCatch(
    warn_unmapped_columns(annotation, "batch", "sample"),
    warning = function(w) conditionMessage(w)
)