| 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 |
ProBatchFeatures objects without dropping metadata.Ensures the [ method returns a ProBatchFeatures instance so the
subclass-specific slots remain available after subsetting.
## S4 method for signature 'ProBatchFeatures,ANY,ANY,ANY' x[i, j, k, ..., drop = TRUE]## S4 method for signature 'ProBatchFeatures,ANY,ANY,ANY' x[i, j, k, ..., drop = TRUE]
x |
A |
i |
Row indices passed to the underlying |
j |
Column indices passed to the underlying |
k |
Assay indices passed to the underlying |
... |
Additional arguments forwarded to the next method. |
drop |
Logical flag controlling dimension dropping; defaults to |
A ProBatchFeatures object containing the requested subset.
Wraps an existing QFeatures instance into the ProBatchFeatures
subclass, initializing the operation log and optional assay renaming when a
single assay is present.
as_ProBatchFeatures( object, level = "feature", pipeline = "raw", sample_id_name = NULL )as_ProBatchFeatures( object, level = "feature", pipeline = "raw", sample_id_name = NULL )
object |
A |
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. |
A ProBatchFeatures object containing the same
assays as object.
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") }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
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 )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 )
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 |
sample_id_col |
name of the column in |
measure_col |
if |
batch_col |
column in |
biospecimen_id_col |
column in |
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 |
pbf_name |
Assay name used when 'df_long' is a 'ProBatchFeatures' object. If 'NULL', [pb_current_assay()] is used. |
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.
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" )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
calculate_peptide_corr_distr( data_matrix, peptide_annotation, protein_col = "ProteinName", feature_id_col = "peptide_group_label", pbf_name = NULL )calculate_peptide_corr_distr( data_matrix, peptide_annotation, protein_col = "ProteinName", feature_id_col = "peptide_group_label", pbf_name = NULL )
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 |
pbf_name |
Assay name used when 'data_matrix' is a 'ProBatchFeatures' object. If 'NULL', [pb_current_assay()] is used. |
dataframe with peptide correlation coefficients
that are suggested to use for plotting in
plot_peptide_corr_distribution as plot_param:
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" )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
## 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", ... )## 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", ... )
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
|
sample_annotation |
data frame with:
.
See |
feature_id_col |
name of the column with feature/gene/peptide/protein
ID used in the long format representation |
sample_id_col |
name of the column in |
factors_for_PVCA |
vector of factors from |
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 |
... |
For |
pbf_name |
Assay name(s) used when |
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.
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 )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").
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 )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 )
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 |
biospecimen_id_col |
column in |
sample_id_col |
name of the column in |
batch_col |
column in |
pbf_name |
Assay name used when 'data_matrix' is a 'ProBatchFeatures' object. If 'NULL', [pb_current_assay()] is used. |
dataframe with the following columns, that
are suggested to use for plotting in
plot_sample_corr_distribution as plot_param:
replicate
batch_the_same
batch_replicate
batches
other columns are:
sample_id_1 & sample_id_2, both
generated from sample_id_col variable
correlation - correlation of two corresponding samples
batch_1 & batch_2 or analogous,
created the same as sample_id_1
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" )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" )
Centers each feature within each batch to the global location (median/mean) of that feature. Works for long-data frames and wide matrices.
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 )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 )
x |
Either a long data.frame or a numeric matrix (features in rows,
samples in columns), depending on |
sample_annotation |
data frame with:
.
See |
format |
One of |
stat |
One of |
sample_id_col |
name of the column in |
batch_col |
column in |
feature_id_col |
name of the column with feature/gene/peptide/protein
ID used in the long format representation |
measure_col |
if |
keep_all |
Passed to |
no_fit_imputed |
If |
qual_col, qual_value
|
Column and value that flag imputed entries. |
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
If format = "long", a data.frame; if format = "wide", a matrix.
# 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 )# 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 )
Use center_feature_batch() with format="long", stat="means".
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 )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 )
df_long |
data frame where each row is a single feature in a single
sample. It minimally has a |
sample_annotation |
data frame with:
.
See |
sample_id_col |
name of the column in |
batch_col |
column in |
feature_id_col |
name of the column with feature/gene/peptide/protein
ID used in the long format representation |
measure_col |
if |
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 |
column to color point by certain value denoted
by |
qual_value |
value in |
A data.frame in long format with batch-corrected
values in measure_col and original values preserved in
preBatchCorr_[measure_col].
# Use the unified replacement with `format = "long"` and `stat = "means"`. args(center_feature_batch)# Use the unified replacement with `format = "long"` and `stat = "means"`. args(center_feature_batch)
Use center_feature_batch() with format="wide", stat="means".
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" )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" )
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
|
sample_annotation |
data frame with:
.
See |
sample_id_col |
name of the column in |
batch_col |
column in |
feature_id_col |
name of the column with feature/gene/peptide/protein
ID used in the long format representation |
measure_col |
if |
A numeric matrix of batch-corrected values
(features samples).
# Use the unified replacement with `format = "wide"` and `stat = "means"`. args(center_feature_batch)# Use the unified replacement with `format = "wide"` and `stat = "means"`. args(center_feature_batch)
Use center_feature_batch() with
format="long", stat="medians".
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 )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 )
df_long |
data frame where each row is a single feature in a single
sample. It minimally has a |
sample_annotation |
data frame with:
.
See |
sample_id_col |
name of the column in |
batch_col |
column in |
feature_id_col |
name of the column with feature/gene/peptide/protein
ID used in the long format representation |
measure_col |
if |
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 |
column to color point by certain value denoted
by |
qual_value |
value in |
A data.frame in long format with batch-corrected
values in measure_col and original values preserved in
preBatchCorr_[measure_col].
# Use the unified replacement with `format = "long"` and `stat = "medians"`. args(center_feature_batch)# Use the unified replacement with `format = "long"` and `stat = "medians"`. args(center_feature_batch)
Use center_feature_batch() with
format="wide", stat="medians".
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" )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" )
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
|
sample_annotation |
data frame with:
.
See |
sample_id_col |
name of the column in |
batch_col |
column in |
feature_id_col |
name of the column with feature/gene/peptide/protein
ID used in the long format representation |
measure_col |
if |
A numeric matrix of batch-corrected values
(features samples).
# Use the unified replacement with `format = "wide"` and `stat = "medians"`. args(center_feature_batch)# 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
check_sample_consistency( sample_annotation, sample_id_col, df_long, batch_col = NULL, order_col = NULL, facet_col = NULL, merge = TRUE )check_sample_consistency( sample_annotation, sample_id_col, df_long, batch_col = NULL, order_col = NULL, facet_col = NULL, merge = TRUE )
sample_annotation |
data frame with:
.
See |
sample_id_col |
name of the column in |
df_long |
data frame where each row is a single feature in a single
sample. It minimally has a |
batch_col |
column in |
order_col |
column in |
facet_col |
column in |
merge |
(logical) whether to merge |
'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.
# 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 )# 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 specified factor columns to factor type and numeric columns to numeric.
convert_annotation_classes(df, factor_columns, numeric_columns)convert_annotation_classes(df, factor_columns, numeric_columns)
df |
data frame with sample annotations. |
factor_columns |
character vector of factor columns. |
numeric_columns |
character vector of numeric columns. |
data frame with converted columns.
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))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 of normalized data to bring each feature within each batch to a comparable scale. The following methods are available:
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.
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.
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.
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.
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 )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 )
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
|
sample_annotation |
data frame with:
.
See |
batch_col |
column in |
feature_id_col |
name of the column with feature/gene/peptide/protein
ID used in the long format representation |
sample_id_col |
name of the column in |
measure_col |
if |
order_col |
column in |
fit_func |
Function used for trend fitting (e.g.,
|
return_fit_df |
Logical; whether |
no_fit_imputed |
(logical) whether to use imputed
(requant) values, as flagged in
|
qual_col |
column to color point by certain value denoted
by |
qual_value |
value in |
min_measurements |
Minimum number of samples per batch required for fitting. |
... |
Further arguments passed to the continuous fitter when enabled
and to |
df_long |
data frame where each row is a single feature in a single
sample. It minimally has a |
keep_all |
when transforming the data (normalize, correct) - acceptable values: all/default/minimal (which set of columns be kept). |
x |
Data in long ( |
format |
One of |
continuous_func |
e.g. |
discrete_func |
batch method name. |
fill_the_missing |
Missing-value policy applied before discrete
correction: |
par.prior |
Logical; use parametric prior (ComBat) or non-parametric. |
covariates_cols |
Optional character vector of
|
fill_value |
Finite numeric scalar used only with
|
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:
corrected_dm — corrected data matrix
fit_df — data frame to inspect fitted curves
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.
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
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 )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 )
Use correct_batch_effects() with format="long".
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 )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 )
df_long |
data frame where each row is a single feature in a single
sample. It minimally has a |
sample_annotation |
data frame with:
.
See |
continuous_func |
e.g. |
discrete_func |
batch method name. |
batch_col |
column in |
feature_id_col |
name of the column with feature/gene/peptide/protein
ID used in the long format representation |
sample_id_col |
name of the column in |
measure_col |
if |
order_col |
column in |
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 |
column to color point by certain value denoted
by |
qual_value |
value in |
fill_the_missing |
Missing-value policy applied before discrete
correction: |
par.prior |
Logical; use parametric prior (ComBat) or non-parametric. |
covariates_cols |
Optional character vector of
|
min_measurements |
Minimum number of samples per batch required for fitting. |
... |
Further arguments forwarded to |
fill_value |
Finite numeric scalar used only with
|
A data.frame in long format with batch-corrected
values in measure_col.
# Use the unified replacement with `format = "long"`. args(correct_batch_effects)# Use the unified replacement with `format = "long"`. args(correct_batch_effects)
Use correct_batch_effects() with format="wide".
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 )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 )
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
|
sample_annotation |
data frame with:
.
See |
continuous_func |
e.g. |
discrete_func |
batch method name. |
batch_col |
column in |
feature_id_col |
name of the column with feature/gene/peptide/protein
ID used in the long format representation |
sample_id_col |
name of the column in |
measure_col |
if |
order_col |
column in |
min_measurements |
Minimum number of samples per batch required for fitting. |
no_fit_imputed |
(logical) whether to use imputed
(requant) values, as flagged in
|
fill_the_missing |
Missing-value policy applied before discrete
correction: |
par.prior |
Logical; use parametric prior (ComBat) or non-parametric. |
covariates_cols |
Optional character vector of
|
... |
Further arguments forwarded to |
fill_value |
Finite numeric scalar used only with
|
A numeric matrix of batch-corrected values
(features samples).
# Use the unified replacement with `format = "wide"`. args(correct_batch_effects)# Use the unified replacement with `format = "wide"`. args(correct_batch_effects)
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).
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 )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 )
x |
Data in long ( |
sample_annotation |
data frame with:
.
See |
feature_id_col |
name of the column with feature/gene/peptide/protein
ID used in the long format representation |
measure_col |
if |
sample_id_col |
name of the column in |
batch_col |
column in |
format |
One of |
par.prior |
Logical; ComBat parametric prior (vs non-parametric). |
covariates_cols |
Optional character vector of
|
fill_the_missing |
Missing-value policy prior to ComBat:
|
keep_all |
For long format, columns to retain (see
|
no_fit_imputed |
If |
qual_col |
column to color point by certain value denoted
by |
qual_value |
value in |
... |
Further arguments passed to |
fill_value |
Finite numeric scalar used only with
|
Matrix if format="wide", data.frame if format="long".
Johnson WE et al. (2007) Biostatistics 8(1):118–127; sva vignette.
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" )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" )
Use correct_with_ComBat() with format="long".
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 )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 )
df_long |
data frame where each row is a single feature in a single
sample. It minimally has a |
sample_annotation |
data frame with:
.
See |
feature_id_col |
name of the column with feature/gene/peptide/protein
ID used in the long format representation |
measure_col |
if |
sample_id_col |
name of the column in |
batch_col |
column in |
par.prior |
Logical; use parametric prior (ComBat) or non-parametric. |
fill_the_missing |
Missing-value policy applied before discrete
correction: |
no_fit_imputed |
(logical) whether to use imputed
(requant) values, as flagged in
|
qual_col |
column to color point by certain value denoted
by |
qual_value |
value in |
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
|
... |
Further arguments passed to |
fill_value |
Finite numeric scalar used only with
|
A data.frame in long format with ComBat-corrected
values in measure_col and original values preserved in
preBatchCorr_[measure_col].
# Use the unified replacement with `format = "long"`. args(correct_with_ComBat)# Use the unified replacement with `format = "long"`. args(correct_with_ComBat)
Use correct_with_ComBat() with format="wide".
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 )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 )
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
|
sample_annotation |
data frame with:
.
See |
feature_id_col |
name of the column with feature/gene/peptide/protein
ID used in the long format representation |
measure_col |
if |
sample_id_col |
name of the column in |
batch_col |
column in |
par.prior |
Logical; use parametric prior (ComBat) or non-parametric. |
fill_the_missing |
Missing-value policy applied before discrete
correction: |
covariates_cols |
Optional character vector of
|
... |
Further arguments passed to |
fill_value |
Finite numeric scalar used only with
|
A numeric matrix of ComBat-corrected values
(features samples).
# Use the unified replacement with `format = "wide"`. args(correct_with_ComBat)# Use the unified replacement with `format = "wide"`. args(correct_with_ComBat)
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).
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 )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 )
x |
Data in long ( |
sample_annotation |
data frame with:
.
See |
feature_id_col |
name of the column with feature/gene/peptide/protein
ID used in the long format representation |
measure_col |
if |
sample_id_col |
name of the column in |
batch_col |
column in |
format |
One of |
covariates_cols |
Optional |
fill_the_missing |
Missing-value policy applied before modeling:
|
keep_all |
For long format, columns to retain (see
|
... |
Further arguments passed to
|
fill_value |
Finite numeric scalar used only with
|
Matrix if format="wide", data.frame if format="long"
with batch effects removed
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" )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" )
Use correct_with_removeBatchEffect() with format="long".
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 )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 )
df_long |
data frame where each row is a single feature in a single
sample. It minimally has a |
sample_annotation |
data frame with:
.
See |
feature_id_col |
name of the column with feature/gene/peptide/protein
ID used in the long format representation |
measure_col |
if |
sample_id_col |
name of the column in |
batch_col |
column in |
covariates_cols |
Optional character vector of
|
fill_the_missing |
Missing-value policy applied before discrete
correction: |
keep_all |
when transforming the data (normalize, correct) - acceptable values: all/default/minimal (which set of columns be kept). |
... |
Further arguments passed to
|
fill_value |
Finite numeric scalar used only with
|
A data.frame in long format with batch effects
removed in measure_col.
# Use the unified replacement with `format = "long"`. args(correct_with_removeBatchEffect)# Use the unified replacement with `format = "long"`. args(correct_with_removeBatchEffect)
Use correct_with_removeBatchEffect() with format="wide".
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 )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 )
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
|
sample_annotation |
data frame with:
.
See |
feature_id_col |
name of the column with feature/gene/peptide/protein
ID used in the long format representation |
measure_col |
if |
sample_id_col |
name of the column in |
batch_col |
column in |
covariates_cols |
Optional character vector of
|
fill_the_missing |
Missing-value policy applied before discrete
correction: |
... |
Further arguments passed to |
fill_value |
Finite numeric scalar used only with
|
A numeric matrix with batch effects removed
(features samples).
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" )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" )
Create light-weight peptide annotation data frame for selection of illustrative proteins
create_peptide_annotation( df_long, feature_id_col = "peptide_group_label", protein_col = c("ProteinName", "Gene") )create_peptide_annotation( df_long, feature_id_col = "peptide_group_label", protein_col = c("ProteinName", "Gene") )
df_long |
data frame where each row is a single feature in a single
sample. It minimally has a |
feature_id_col |
name of the column with feature/gene/peptide/protein
ID used in the long format representation |
protein_col |
column where protein names are specified |
data frame containing peptide annotations
plot_peptides_of_one_protein,
plot_protein_corrplot
data("example_proteome", package = "proBatch") generated_peptide_annotation <- create_peptide_annotation( example_proteome, feature_id_col = "peptide_group_label", protein_col = c("Protein") )data("example_proteome", package = "proBatch") generated_peptide_annotation <- create_peptide_annotation( example_proteome, feature_id_col = "peptide_group_label", protein_col = c("Protein") )
Converts date/time columns for sample_annotation to POSIXct format and calculates sample run rank in order column
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" )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" )
sample_annotation |
data frame with:
.
See |
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 |
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 |
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)
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 )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 column of sample_annotation to POSIX format required to keep number-like behavior
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" )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" )
sample_annotation |
data frame with:
.
See |
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 |
tz |
for time zone, 'GMT' by default |
locale |
for locale, 'en_US.UTF-8' by default |
sample annotation file with a new column new_time_column with
POSIX-formatted date
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") )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
define_sample_order( order_col, sample_annotation, facet_col, batch_col, df_long, sample_id_col, color_by_batch )define_sample_order( order_col, sample_annotation, facet_col, batch_col, df_long, sample_id_col, color_by_batch )
order_col |
column in |
sample_annotation |
data frame with:
.
See |
facet_col |
column in |
batch_col |
column in |
df_long |
data frame where each row is a single feature in a single
sample. It minimally has a |
sample_id_col |
name of the column in |
color_by_batch |
(logical) whether to color points and connecting lines
by batch factor as defined by |
list of two items: order_col new name and new df_long
plot_sample_mean_or_boxplot, feature_level_diagnostics
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_longdata( 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
detect_nested_batches(sample_annotation, batch_cols)detect_nested_batches(sample_annotation, batch_cols)
sample_annotation |
data frame with sample annotations. |
batch_cols |
character vector with two or more batch variables. |
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".
data("example_ecoli_data", package = "proBatch") meta <- example_ecoli_data$all_metadata detect_nested_batches(meta, batch_cols = c("Lab", "Condition"))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
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 )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 )
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
|
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 |
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. |
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.
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 )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 )
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).
A named list with four elements:
'data.frame' (118 rows × 3 columns) with per-sample annotation. Columns: 'Run', 'Lab', and 'Condition'.
'data.frame' (1463 rows × 118 columns) containing the combined precursor-level Precursor.Normalised intensities (rows = precursors, columns = samples).
'data.frame' (400 rows × 118 columns) containing the combined protein group-level PG.MaxLFQ intensities.
'data.frame' (1463 rows × 2 columns) linking 'Precursor.Id' to 'Protein.Ids'.
A named list containing the combined metadata, quantification matrices, and precursor-to-protein mapping.
PRIDE ID PXD053812
data("example_ecoli_data", package = "proBatch") names(example_ecoli_data)data("example_ecoli_data", package = "proBatch") names(example_ecoli_data)
This is data from Aging study annotated with gene names
A data frame with 366 rows and 3 variables:
peptide group label ID, identical to
peptide_group_label in example_proteome
HUGO gene ID
protein group name as specified in
example_proteome
A data frame with 366 rows and 3 variables.
data("example_peptide_annotation", package = "proBatch") head(example_peptide_annotation)data("example_peptide_annotation", package = "proBatch") head(example_peptide_annotation)
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
A data frame with 85278 rows and 5 variables:
peptide ID, which is regular feature level.
This column is mostly used as feature_id_col
used for merging with
"example_peptide_annotation"
peptide group intensity in given sample.
Used in function as measure_col
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
name of the file, in most functions used for
sample_id_col
logical column marking peptide-identification quality,
usable as qual_col
...
A data frame with 85278 rows and 5 variables.
PRIDE ID will be added upon the publication of the dataset
data("example_proteome", package = "proBatch") head(example_proteome)data("example_proteome", package = "proBatch") head(example_proteome)
This is measurement data from Aging study with columns representing samples
and rows representing peptides. Generated by long_to_matrix
A matrix with 366 rows and 233 columns:
A matrix with 366 rows and 233 columns.
PRIDE ID will be added upon the publication of the dataset
data("example_proteome_matrix", package = "proBatch") dim(example_proteome_matrix)data("example_proteome_matrix", package = "proBatch") dim(example_proteome_matrix)
This is data from BXD mouse population aging study with mock instruments to show how instrument-specific functionality works
A data frame with 233 rows and 11 variables:
name of the file with the measurement for each sample,
referred to as sample_id_col
mass-spectrometry batch: character vector with four manually annotated batch labels
mouse ID, i.e. ID of the biological object. Only 14 mice have been replicated, one mouse was profiled 7 times.
mouse strain ID from BXD population set - biological covariate #1, 51 Strain represented
diet, biological covariate #2 - either
HF = 'High Fat Diet' or CD = 'Chow Diet'
mice sex - biological covariate #3
mass-spectrometry running date. In combination
with RunTime used for running order determination. Character
vector
mass-spectrometry running time. In combination
with RunDate used for running order determination. Character
vector
date and time of class "POSIXct"/"POSIXt"
generated by date_to_sample_order
order of samples generated by sorting DateTime
in date_to_sample_order
numeric peptide digestion batch with four manually annotated values
...
A data frame with 233 rows and 11 variables.
data("example_sample_annotation", package = "proBatch") head(example_sample_annotation)data("example_sample_annotation", package = "proBatch") head(example_sample_annotation)
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
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 )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 )
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:
.
See |
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 |
measure_col |
if |
feature_id_col |
name of the column with feature/gene/peptide/protein
ID used in the long format representation |
geom |
whether to show the feature as points and/or connect by lines
(accepted values are: 1. |
qual_col |
column to color point by certain value denoted
by |
qual_value |
value in |
batch_col |
column in |
color_by_batch |
(logical) whether to color points and connecting lines
by batch factor as defined by |
color_scheme |
a named vector of colors to map to |
order_col |
column in |
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 |
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 |
ylimits |
range of y-axis to plot feature-level trends |
base_size |
base font size |
protein_name |
name of the protein as defined in |
peptide_annotation |
long format data frame with peptide ID and their
corresponding protein and/or gene annotations. See
|
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
|
fit_df |
data frame output of |
fit_value_col |
column in |
ggplot2 type plot of measure_col vs order_col,
faceted by feature_name and (optionally) by facet_col
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 )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 )
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.
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, ... )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, ... )
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. |
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'.
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)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)
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.
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, ... )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, ... )
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. |
A list of character vectors (each of length two) naming duplicated column pairs. An empty list is returned when no duplicates are detected.
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)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)
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, ... )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, ... )
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 |
order_col |
column in |
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
|
optimize_span |
logical, whether to specify span or optimize it (specific entirely for LOESS regression) |
no_fit_imputed |
logical; when |
qual_col |
column to color point by certain value denoted
by |
qual_value |
value in |
min_measurements |
minimum length of a consecutive non-missing run
required to fit a curve. Shorter runs return an all- |
... |
additional parameters to be passed to the fitting function |
vector of fitted response values
# 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])# 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"
get_chain(object, as_string = FALSE, assay = NULL)get_chain(object, as_string = FALSE, assay = NULL)
object |
A |
as_string |
logical(1). if |
assay |
Optional assay identifier. When supplied, derive that assay's
lineage from operation-log edges. When |
Logged lineage is validated before a chain is returned. Ambiguous
or cyclic lineage causes an error, including when assay = NULL.
Character vector or string describing the processing chain.
# 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" )# 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)
get_operation_log(object)get_operation_log(object)
object |
A |
S4Vectors::DataFrame
# 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" )# 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" )
Derive numeric columns from factor columns if guess_factors is TRUE and numeric columns are NULL.
guess_factor_columns_if_needed( factor_columns, sample_annotation, guess_factors )guess_factor_columns_if_needed( factor_columns, sample_annotation, guess_factors )
factor_columns |
character vector of factor columns. |
sample_annotation |
data frame of sample annotations. |
guess_factors |
logical indicating whether to guess numeric columns. |
Named list containing updated factor_columns and numeric_columns.
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 ) guessedannotation <- 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
Remove numeric columns from factor columns if overlap is detected.
handle_factor_numeric_overlap(factor_columns, numeric_columns)handle_factor_numeric_overlap(factor_columns, numeric_columns)
factor_columns |
character vector of factor columns. |
numeric_columns |
character vector of numeric columns. |
A character vector containing factor_columns after any
columns in numeric_columns have been removed.
factor_columns <- c("batch", "injection_order") overlap_result <- handle_factor_numeric_overlap( factor_columns, numeric_columns = "injection_order" ) overlap_resultfactor_columns <- c("batch", "injection_order") overlap_result <- handle_factor_numeric_overlap( factor_columns, numeric_columns = "injection_order" ) overlap_result
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.
handle_missing_values( data_matrix, warning_message, fill_the_missing = "error", fill_value = NULL )handle_missing_values( data_matrix, warning_message, fill_the_missing = "error", fill_value = NULL )
data_matrix |
Numeric feature-by-sample matrix. |
warning_message |
Error message used when missing values are present
under the default |
fill_the_missing |
One of |
fill_value |
Finite numeric scalar used only with
|
A numeric matrix with the requested missing-value policy applied.
mat <- matrix(c(1, NA, 3, 4), nrow = 2) handle_missing_values( mat, warning_message = "demo", fill_the_missing = "fill", fill_value = 0 )mat <- matrix(c(1, NA, 3, 4), nrow = 2) handle_missing_values( mat, warning_message = "demo", fill_the_missing = "fill", fill_value = 0 )
Convert from a long data frame representation to a wide matrix representation
long_to_matrix( df_long, feature_id_col = "peptide_group_label", measure_col = "Intensity", sample_id_col = "FullRunName", qual_col = NULL, qual_value = 2 )long_to_matrix( df_long, feature_id_col = "peptide_group_label", measure_col = "Intensity", sample_id_col = "FullRunName", qual_col = NULL, qual_value = 2 )
df_long |
data frame where each row is a single feature in a single
sample. It minimally has a |
feature_id_col |
name of the column with feature/gene/peptide/protein
ID used in the long format representation |
measure_col |
if |
sample_id_col |
name of the column in |
qual_col |
column to color point by certain value denoted
by |
qual_value |
value in |
data_matrix (proBatch) like matrix
(features in rows, samples in columns)
Other matrix manipulation functions:
matrix_to_long()
data("example_proteome", package = "proBatch") proteome_matrix <- long_to_matrix(example_proteome)data("example_proteome", package = "proBatch") proteome_matrix <- long_to_matrix(example_proteome)
Convert from wide matrix to a long data frame representation
matrix_to_long( data_matrix, sample_annotation = NULL, feature_id_col = "peptide_group_label", measure_col = "Intensity", sample_id_col = "FullRunName", step = NULL )matrix_to_long( data_matrix, sample_annotation = NULL, feature_id_col = "peptide_group_label", measure_col = "Intensity", sample_id_col = "FullRunName", step = NULL )
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
|
sample_annotation |
data frame with:
.
See |
feature_id_col |
name of the column with feature/gene/peptide/protein
ID used in the long format representation |
measure_col |
if |
sample_id_col |
name of the column in |
step |
normalization step (e.g. |
df_long (proBatch) like data frame
Other matrix manipulation functions:
long_to_matrix()
# 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 )# 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 )
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.
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, ... )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, ... )
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. |
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.
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)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)
Normalization of raw (usually log-transformed) data. Normalization brings the samples to the same scale. Currently the following normalization functions are implemented:
Quantile normalization: 'quantile_normalize_dm()'. Quantile normalization of the data.
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.
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" )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" )
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
|
df_long |
data frame where each row is a single feature in a single
sample. It minimally has a |
feature_id_col |
name of the column with feature/gene/peptide/protein
ID used in the long format representation |
sample_id_col |
name of the column in |
measure_col |
if |
no_fit_imputed |
(logical) whether to use imputed
(requant) values, as flagged in
|
qual_col |
column to color point by certain value denoted
by |
qual_value |
value in |
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 |
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.
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 )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
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 )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 )
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
|
mapping_df |
Data frame mapping |
from_id |
Source-ID column in |
to_id |
Target-ID column in |
map_strategy |
how to resolve multiple to-ids per from-id:
|
link_var |
rowData variable name to use for linking (e.g., "ProteinID") |
backend |
"memory","hdf5","auto" |
hdf5_path |
optional filepath for HDF5Array |
ProBatchFeatures with new assay and link added
# 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" )# 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
pb_aggregate_level( object, from, feature_var, fun = colMedians, new_level = "protein", new_pipeline = NULL )pb_aggregate_level( object, from, feature_var, fun = colMedians, new_level = "protein", new_pipeline = NULL )
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') |
ProBatchFeatures with an additional aggregated assay appended
# 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" )# 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" )
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.
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", ... )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", ... )
x |
Numeric feature-by-sample matrix or long data frame.
|
fun |
Function or registered step identifier. The method receives the
numeric matrix as its first argument. Aligned |
sample_annotation |
Optional data frame aligned by
|
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. |
fill_value |
Finite numeric scalar used only with
|
keep_all |
Long-output column policy. |
... |
Additional arguments forwarded to |
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.
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" )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)
pb_as_long( object, feature_id_col = "feature_label", sample_id_col = "FullRunName", measure_col = "Intensity", pbf_name = pb_current_assay(object) )pb_as_long( object, feature_id_col = "feature_label", sample_id_col = "FullRunName", measure_col = "Intensity", pbf_name = pb_current_assay(object) )
object |
A |
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. |
tibble/data.frame containing one row per feature-sample combination
# 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" )# 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)
pb_as_wide(object, assay = pb_current_assay(object), name = "intensity")pb_as_wide(object, assay = pb_current_assay(object), name = "intensity")
object |
A |
assay |
Assay identifier to extract; defaults to the current assay. |
name |
Assay entry name inside the |
Numeric matrix-like data corresponding to the requested assay.
HDF5-backed assays may return a DelayedMatrix without coercion.
# 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" )# 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" )
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.
pb_assay_matrix(object, assay = NULL, name = "intensity")pb_assay_matrix(object, assay = NULL, name = "intensity")
object |
A |
assay |
Assay identifier to extract; defaults to the current assay. |
name |
Assay entry to read from the underlying |
Assay data with features in rows and samples in columns. In-memory
assays return a matrix; HDF5-backed assays may return a DelayedMatrix.
# 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" )# 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
pb_current_assay(object)pb_current_assay(object)
object |
A |
character(1) assay identifier for the most recently stored assay
# 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" )# 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
pb_eval(object, from, steps, funs = NULL, params_list = NULL)pb_eval(object, from, steps, funs = NULL, params_list = NULL)
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: |
params_list |
list of parameter lists (same length as steps) |
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.
# 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" )# 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" )
Canonical names and aliases resolve to the same registration.
pb_has_step(name, available = FALSE)pb_has_step(name, available = FALSE)
name |
One canonical step name or alias. |
available |
Logical scalar. If |
A logical scalar.
pb_has_step("medianNorm") pb_has_step("combat", available = TRUE)pb_has_step("medianNorm") pb_has_step("combat", available = TRUE)
Returns canonical step names. Pattern matching considers canonical names, aliases, and display labels. Availability filtering reports current state without changing registrations.
pb_list_steps(pattern = NULL, details = FALSE, available = NULL)pb_list_steps(pattern = NULL, details = FALSE, available = NULL)
pattern |
Optional regular expression used to filter canonical names, aliases, and labels. |
details |
Logical scalar. If |
available |
Optional logical scalar. Use |
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.
pb_list_steps() pb_list_steps(details = TRUE) pb_list_steps("^l")pb_list_steps() pb_list_steps(details = TRUE) pb_list_steps("^l")
QFeatures missing-data helpers to stored assaysThese 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.
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, ... )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, ... )
object |
A |
pbf_name |
Character vector of assay names. Defaults to
|
... |
Additional parameters forwarded to the underlying
|
inplace |
Logical (used by |
final_name |
Character (used by |
group_cols |
Character vector (used by |
min_valid |
Integer scalar (used by |
pNA |
Numeric scalar (used by |
mask_failing |
Logical scalar (used by |
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.
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.
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"]])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
pb_pipeline_name(object, assay = pb_current_assay(object))pb_pipeline_name(object, assay = pb_current_assay(object))
object |
ProBatchFeatures |
assay |
character(1) assay name; defaults to current assay |
The operation-log lineage must be unambiguous and acyclic.
character(1) pipeline string like
"combat_on_medianNorm_on_log2_on_raw" or "raw"
# 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" )# 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" )
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.
pb_register_step( name, fun, package = NULL, kind = "transform", requires = character(), aliases = character(), label = name )pb_register_step( name, fun, package = NULL, kind = "transform", requires = character(), aliases = character(), label = name )
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 |
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 |
label |
One non-missing, non-empty display label. |
TRUE, invisibly.
# 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" )# 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" )
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.
pb_step_result(data, artifacts = list())pb_step_result(data, artifacts = list())
data |
Transformed data produced by a method. |
artifacts |
A list of structured artifacts associated with |
An object of class pb_step_result with data and
artifacts components.
result <- pb_step_result( matrix(1:4, nrow = 2), artifacts = list(converged = TRUE) ) result$data result$artifactsresult <- pb_step_result( matrix(1:4, nrow = 2), artifacts = list(converged = TRUE) ) result$data result$artifacts
ProBatchFeatures metadata.Resolve sample metadata from colData(object), build a column mask, and
delegate to the subclass-preserving [ method so every
assay is subset consistently.
pb_subset_samples( object, sample_id_col = "FullRunName", subset_by = sample_id_col, subset_values )pb_subset_samples( object, sample_id_col = "FullRunName", subset_by = sample_id_col, subset_values )
object |
A |
sample_id_col |
Character scalar naming the sample identifier column in
|
subset_by |
Character scalar naming the metadata column used for
filtering. Defaults to |
subset_values |
Values to retain from |
A ProBatchFeatures object restricted to the selected samples.
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" )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
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 )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 )
object |
A |
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: |
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 |
fast_steps |
Steps treated as fast (default:
|
store_intermediate |
logical; if TRUE store every step (overrides fast behavior) |
final_name |
Optional final assay name override in
|
backend |
"memory","hdf5","auto" |
hdf5_path |
Optional file path used when |
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.
ProBatchFeatures with the requested pipeline added (as log and/or assay)
# 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" )# 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" )
Removes every canonical registration and alias owned by package. Calling
the function when the provider owns no registrations is a no-op.
pb_unregister_steps(package)pb_unregister_steps(package)
package |
One non-missing, non-empty provider package name. |
The removed canonical names, invisibly.
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" ) ) })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" ) ) })
recommended for heatmap-type visualisation of correlation matrix with <100 items. With >50 samples and ~10 replicate pairs distribution plots may be more informative.
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, ... )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, ... )
corr_matrix |
square correlation matrix |
annotation |
data frame with |
annotation_id_col |
|
factors_to_plot |
vector of technical and biological covariates to be
plotted in this diagnostic plot (assumed to be present in
|
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 |
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 |
Plot correlation of selected samples or peptides
pheatmap object
pheatmap,
plot_sample_corr_distribution,
plot_peptide_corr_distribution
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)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
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 )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 )
df_long |
as in |
sample_annotation |
data frame with:
.
See |
feature_id_col |
name of the column with feature/gene/peptide/protein
ID used in the long format representation |
sample_id_col |
name of the column in |
measure_col |
if |
biospecimen_id_col |
column in |
batch_col |
column in |
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 |
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 |
pbf_name |
Assay name to transform when 'x' is a 'ProBatchFeatures'. |
If 'batch_col' is supplied and per-batch CV is available, 'plot_CV_distr()' plots 'CV_perBatch' across batches. Otherwise it plots 'CV_total'.
ggplot object with the boxplot of CVs on one or several steps
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" )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
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") )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") )
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 |
log_y_scale |
(logical) whether to display the CV on log-scale |
batch_col |
optional batch column in |
value_col |
which CV column to plot: |
ggplot object
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)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)
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.
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, ... )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, ... )
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. |
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.
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 )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)
## 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, ... )## 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, ... )
data_matrix |
Input object: matrix-like data or a
|
sample_annotation |
data frame with:
.
See |
sample_id_col |
name of the column in |
factors_to_plot |
vector of technical and biological factors to be
plotted in this diagnostic plot (assumed to be present in
|
fill_the_missing |
numeric value that the missing values are
substituted with, or |
color_for_missing |
special color to make missing values.
Usually black or white, depending on |
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 |
peptide_annotation |
long format data frame with peptide ID and their
corresponding protein and/or gene annotations. See
|
feature_id_col |
name of the column with feature/gene/peptide/protein
ID used in the long format representation |
factors_of_feature_ann |
vector of factors that characterize features,
as listed in |
color_list_features |
list, as returned by
|
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 |
pbf_name |
Assay name(s) used when |
return_gridExtra |
Logical; for multiple assays, return an invisible
list with |
plot_ncol |
Number of columns when arranging multiple assay plots. |
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.
sample_annotation_to_colors,
pheatmap
# 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 )# 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
## 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, ... )## 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, ... )
data_matrix |
Input object: matrix-like data or a
|
column_annotation_df |
data frame annotating columns of
|
row_annotation_df |
data frame annotating rows of |
col_ann_id_col |
column of |
row_ann_id_col |
column of |
columns_for_cols |
vector of factors (columns) of
|
columns_for_rows |
vector of factors (columns) of
|
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 |
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 |
fill_the_missing |
numeric value that the missing values are
substituted with, or |
color_for_missing |
special color to make missing values.
Usually black or white, depending on |
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 |
pbf_name |
Assay name(s) used when |
return_gridExtra |
Logical; for multiple assays, return an invisible
list with |
plot_ncol |
Number of columns when arranging multiple assay plots. |
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.
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 )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
## 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, ... )## 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, ... )
data_matrix |
Input object: matrix-like data or a
|
sample_annotation |
data frame with:
.
See |
sample_id_col |
name of the column in |
color_list |
list, as returned by |
factors_to_plot |
vector of technical and biological covariates to be
plotted in this diagnostic plot (assumed to be present in
|
fill_the_missing |
numeric value determining how missing values
should be substituted. If |
distance |
distance metric used for clustering |
agglomeration |
agglomeration methods as used by |
label_samples |
if |
label_font |
size of the font. Is active if |
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 |
... |
other parameters of |
pbf_name |
Assay name(s) used when |
return_gridExtra |
logical; when plotting multiple assays from a
|
plot_ncol |
optional integer controlling the number of columns when arranging multiple assays. Ignored by the default method. |
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.
hclust,
sample_annotation_to_colors,
plotDendroAndColors
# 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 )# 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 )
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'.
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", ... )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", ... )
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. |
A 'ggplot' object.
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)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)
Display how many features are observed in a given number of samples.
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, ... )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, ... )
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. |
A 'ggplot' object showing the frequency distribution.
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 )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 )
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.
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, ... )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, ... )
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). |
For a grouped view that collapses samples by metadata and shows within-group observed fractions, see [plot_grouped_NA_heatmap()].
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.
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 )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 )
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.
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", ... )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", ... )
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. |
A 'ggplot' object.
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")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
## 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, ... )## 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, ... )
data_matrix |
Numeric feature-by-sample matrix or a
|
sample_annotation |
data frame with:
.
See |
feature_id_col |
name of the column with feature/gene/peptide/protein
ID used in the long format representation |
sample_id_col |
name of the column in |
color_by |
Column name in |
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
|
color_scheme |
a named vector of colors to map to |
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 |
base_size |
base size of the text in the plot |
point_size |
Point size supplied to |
point_alpha |
Alpha transparency for plotted points. |
marginal_density |
Logical or a single column name. If |
x_nPC |
Optional integer PC index for the x axis.
Use together with |
y_nPC |
Optional integer PC index for the y axis.
Use together with |
... |
For |
pbf_name |
Assay name(s) used when |
return_gridExtra |
Logical; for multiple assays, return an invisible
list containing the arranged |
plot_ncol |
Number of columns when arranging multiple assay plots. |
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.
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)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)
Plot distribution of peptide correlations within one protein and between proteins
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 )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 )
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 |
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 |
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 |
ggplot object (violin plot of peptide correlation)
calculate_peptide_corr_distr,
ggplot
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)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)
Plots correlation plot of peptides from a single protein
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, ... )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, ... )
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
|
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
|
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 |
factors_to_plot |
vector of technical and biological covariates to be
plotted in this diagnostic plot (assumed to be present in
|
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 |
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 |
pheatmap object
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" )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
## 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, ... )## 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, ... )
data_matrix |
Input object: matrix-like data or a
|
sample_annotation |
data frame with:
.
See |
feature_id_col |
name of the column with feature/gene/peptide/protein
ID used in the long format representation |
sample_id_col |
name of the column in |
technical_factors |
vector |
biological_factors |
vector |
fill_the_missing |
numeric value determining how missing values
should be substituted. If |
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 |
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 |
pbf_name |
Assay name(s) used when |
return_gridExtra |
Logical; for multiple assays, return an invisible
list with |
plot_ncol |
Number of columns when arranging multiple assay plots. |
stacked_bar |
logical; when |
stacked_plot_title |
optional character vector
that annotates the stacked PVCA plot when |
sort_stacked |
optional factor name used to order stacked bars when
|
category_order |
optional character vector specifying the category order in a stacked PVCA plot. |
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.
sample_annotation_to_colors,
ggplot
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)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)
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.
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 )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 )
pvca_dir |
Directory that contains per-assay
|
sort_stacked |
Optional factor label used to order the rows of the
stacked plot (matching |
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 |
Optional character vector used as the stacked plot
title; elements are joined with newline characters. Its non- |
theme |
Plot theme; only |
base_size |
Base font size passed to |
filename |
Optional path to save the stacked plot. |
width |
Plot width forwarded to |
height |
Plot height forwarded to |
units |
Plot units forwarded to |
category_order |
Optional character vector specifying the order of categories in the stacked plot. |
A ggplot object showing the stacked PVCA weights.
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) })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
## 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, ... )## 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, ... )
data_matrix |
Data frame of PVCA weights, typically the result of
|
pbf_name |
Assay name(s) used when |
sample_annotation |
data frame with:
.
See |
feature_id_col |
name of the column with feature/gene/peptide/protein
ID used in the long format representation |
sample_id_col |
name of the column in |
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 |
base_size |
base size of the text in the plot |
return_gridExtra |
Logical; for multiple assays, return an invisible
list with |
plot_ncol |
Number of columns when arranging multiple assay plots. |
... |
Additional arguments. For a |
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.
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.
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 )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 )
Useful to visualize within batch vs within replicate vs non-related sample correlation
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 )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 )
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 |
sample_id_col |
name of the column in |
batch_col |
column in |
biospecimen_id_col |
column in |
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
|
theme |
ggplot theme, by default |
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 |
base_size |
base font size |
ggplot type object with violin plot
for each plot_param
calculate_sample_corr_distr,
ggplot
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" )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" )
Plot correlation of selected samples
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, ... )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, ... )
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
|
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 |
factors_to_plot |
vector of technical and biological covariates to be
plotted in this diagnostic plot (assumed to be present in
|
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 |
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 object for a single assay, or an arranged plot object
when multiple assays are plotted.
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 )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 means or boxplots showing medians and quantiles. For ordered samples, such as consecutive mass-spectrometry runs, the plots show order-associated effects.
## 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, ...)## 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, ...)
x |
Input supplied to the generics: a matrix, long data frame, or 'ProBatchFeatures' object. |
sample_annotation |
data frame with:
.
See |
sample_id_col |
name of the column in |
batch_col |
column in |
color_by_batch |
(logical) whether to color points and connecting lines
by batch factor as defined by |
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 |
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 |
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 |
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'. |
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.
[ggplot2::ggplot()], [date_to_sample_order()]
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" )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)
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" )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" )
df |
data.frame with |
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 |
ggplot object
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" )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" )
Compute t-SNE with samples as observations (matrix columns) and return a
static ggplot by default. Interactive Plotly rendering is optional.
## 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, ...)## 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, ...)
data_matrix |
Numeric feature-by-sample matrix or a
|
sample_annotation |
data frame with:
.
See |
feature_id_col |
name of the column with feature/gene/peptide/protein
ID used in the long format representation |
sample_id_col |
name of the column in |
color_by |
Column name in |
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
|
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
|
color_scheme |
a named vector of colors to map to |
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 |
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 |
use_plotlyrender |
Logical; return a |
theme_name |
Plot theme name. Only |
base_size |
base size of the text in the plot |
plotly_param |
Named list of optional arguments such as |
... |
Named backend arguments forwarded to |
pbf_name |
Assay name(s) used when |
assay_args |
|
return_gridExtra |
Logical; for multiple assays, return an invisible
list containing the arranged |
plot_ncol |
Number of columns when arranging multiple assay plots. |
return_subplots |
Logical; combine multiple interactive assay plots with
|
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. |
Each input assay must contain at least two samples.
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.
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 ) }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 ) }
Compute UMAP with samples as observations (matrix columns) and return a
static ggplot by default. Interactive Plotly rendering is optional.
## 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, ...)## 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, ...)
data_matrix |
Numeric feature-by-sample matrix or a
|
sample_annotation |
data frame with:
.
See |
feature_id_col |
name of the column with feature/gene/peptide/protein
ID used in the long format representation |
sample_id_col |
name of the column in |
color_by |
Column name in |
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 |
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
|
color_scheme |
a named vector of colors to map to |
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 |
point_alpha |
Alpha transparency for plotted points. |
random_state |
Optional integer placed in the UMAP configuration for
reproducible coordinates. When |
spread |
Optional positive numeric UMAP spread. |
learning_rate |
Optional positive numeric UMAP learning rate, forwarded
as the backend configuration's |
use_plotlyrender |
Logical; return a |
theme_name |
Plot theme name. Only |
base_size |
base size of the text in the plot |
plotly_param |
Named list of optional arguments such as |
... |
Named backend arguments forwarded to |
pbf_name |
Assay name(s) used when |
assay_args |
|
return_gridExtra |
Logical; for multiple assays, return an invisible
list containing the arranged |
plot_ncol |
Number of columns when arranging multiple assay plots. |
return_subplots |
Logical; combine multiple interactive assay plots with
|
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. |
Each input assay must contain at least two samples.
For matrix input, a ggplot or, when requested, a plotly object.
Multi-assay return behavior matches plot_TSNE().
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 ) }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
## 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", ... )## 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", ... )
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
|
sample_annotation |
data frame with:
.
See |
feature_id_col |
name of the column with feature/gene/peptide/protein
ID used in the long format representation |
sample_id_col |
name of the column in |
technical_factors |
vector |
biological_factors |
vector |
fill_the_missing |
numeric value determining how missing values
should be substituted. If |
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 |
... |
Additional arguments forwarded between methods. |
pbf_name |
Assay name(s) used when |
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.
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 )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 )
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.
df_long |
data frame where each row is a single feature in a single
sample. It minimally has a |
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
|
sample_annotation |
data frame with:
.
See |
sample_id_col |
name of the column in |
measure_col |
if |
feature_id_col |
name of the column with feature/gene/peptide/protein
ID used in the long format representation |
batch_col |
column in |
order_col |
column in |
facet_col |
column in |
color_by_batch |
(logical) whether to color points and connecting lines
by batch factor as defined by |
peptide_annotation |
long format data frame with peptide ID and their
corresponding protein and/or gene annotations. See
|
color_scheme |
a named vector of colors to map to |
color_list |
list, as returned by |
factors_to_plot |
vector of technical and biological covariates to be
plotted in this diagnostic plot (assumed to be present in
|
protein_col |
column where protein names are specified |
no_fit_imputed |
(logical) whether to use imputed
(requant) values, as flagged in
|
qual_col |
column to color point by certain value denoted
by |
qual_value |
value in |
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 |
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 |
To learn more about proBatch, start with the vignettes:
browseVignettes(package = "proBatch")
No return value.
Common arguments to the functions.
Maintainer: Yuliya Burankova [email protected]
Authors:
Jelena Cuklina [email protected]
Chloe H. Lee [email protected]
Patrick Pedrioli [email protected]
Olga Zolotareva [email protected]
Useful links:
if (interactive()) { browseVignettes(package = "proBatch") }if (interactive()) { browseVignettes(package = "proBatch") }
Construct a ProBatchFeatures object from a wide matrix + sample annotation.
ProBatchFeatures( data_matrix, sample_annotation = NULL, sample_id_col = "FullRunName", name = NULL, level = "feature" )ProBatchFeatures( data_matrix, sample_annotation = NULL, sample_id_col = "FullRunName", name = NULL, level = "feature" )
data_matrix |
numeric matrix (features x samples) |
sample_annotation |
Optional data frame with sample metadata (rows =
samples). When |
sample_id_col |
Character scalar naming the column in
|
name |
Optional non-missing, non-empty character scalar. A pipeline
shorthand is combined with |
level |
character label like "peptide"/"protein" (default "feature"). |
A ProBatchFeatures object.
# 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" )# 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
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 )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 )
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 |
sample_id_col |
Column containing sample identifiers in |
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 |
A ProBatchFeatures object constructed from the long-format input.
# 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" )# 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" )
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".
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.
No return value; defines the ProBatchFeatures S4 class.
chaincharacter() ordered list of steps (e.g., c("log","medianNorm","combat")).
oplogS4Vectors::DataFrame with columns: - step (character), fun (character), from (character), to (character), params (list), timestamp (POSIXct), pkg (character)
# 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" )# 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" )
Convert the sample annotation data frame to list of colors the list is named as columns included to use in plotting functions
## 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, ...)## 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, ...)
sample_annotation |
Input object supplied to the generic (data frame or 'ProBatchFeatures'). |
sample_id_col |
name of the column in |
factor_columns |
columns of |
numeric_columns |
columns of |
rare_categories_to_other |
if |
guess_factors |
whether attempt which of the |
numeric_palette_type |
palette to be used for
numeric values coloring (can be |
... |
Additional arguments forwarded to method implementations. |
list of colors for the selected annotation columns. Use
color_list_to_df if a data frame representation is needed.
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") )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
subbatch_detection( data_matrix, sample_annotation, batch_col, n_pcs = 10, method = c("hclust", "kmeans"), k_max = 6, pbf_name = NULL )subbatch_detection( data_matrix, sample_annotation, batch_col, n_pcs = 10, method = c("hclust", "kmeans"), k_max = 6, pbf_name = NULL )
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
|
sample_annotation |
data frame with:
.
See |
batch_col |
column in |
n_pcs |
number of principal components to use. |
method |
clustering method; |
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. |
A list with per-sample assignments, per-batch summaries, and
suggestions. The object has class "pb_subbatches".
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 )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
summarize_design( sample_annotation, batch_col, condition_col = NULL, covariates = NULL, add_intercept = TRUE )summarize_design( sample_annotation, batch_col, condition_col = NULL, covariates = NULL, add_intercept = TRUE )
sample_annotation |
data frame with:
.
See |
batch_col |
column in |
condition_col |
optional column in |
covariates |
optional character vector of additional covariate columns. |
add_intercept |
logical; include intercept in the design matrix. |
A list with design diagnostics: design_matrix_dim,
rank, deficiency, kappa, aliased_terms,
flagged_covariates, and notes. The object has class
"pb_design_summary".
data("example_ecoli_data", package = "proBatch") meta <- example_ecoli_data$all_metadata summarize_design( meta, batch_col = "Lab", condition_col = "Condition", add_intercept = TRUE )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
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.
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, ...)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, ...)
df_long |
data frame where each row is a single feature in a single
sample. It minimally has a |
log_base |
base of the logarithm for transformation |
offset |
small positive number to prevent 0 conversion to |
measure_col |
if |
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. |
'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()].
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 )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
validate_batch_design( sample_annotation, batch_col, condition_col = NULL, covariates = NULL, sample_id_col = NULL, strict = TRUE )validate_batch_design( sample_annotation, batch_col, condition_col = NULL, covariates = NULL, sample_id_col = NULL, strict = TRUE )
sample_annotation |
data frame with:
.
See |
batch_col |
column in |
condition_col |
optional column in |
covariates |
optional character vector of additional covariate columns. |
sample_id_col |
name of the column in |
strict |
logical; when |
A list with errors, warnings, and summary. The
object has class "pb_design_check".
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 )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 )
Emit a warning if some columns will not be mapped to colors.
warn_unmapped_columns( sample_annotation, columns_for_color_mapping, sample_id_col )warn_unmapped_columns( sample_annotation, columns_for_color_mapping, sample_id_col )
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. |
No return value, called for side effects (warning).
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) )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) )