Flags contaminant features by comparing the median values of blanks and biological samples. Biological sampels are defined as samples that are not marked as blanks and are not QCs. If the median of blanks > the median of biological samples times a set ratio, the feature is flagged as contaminant.
Usage
flag_contaminants(
object,
blank_col,
blank_label,
flag_thresh = 0.05,
flag_label = "Contaminant",
assay.type = NULL
)
Arguments
- object
a
SummarizedExperiment
orMetaboSet
object- blank_col
character, the column name in pheno data with blank labels
- blank_label
character, the label for blank samples in blank_col
- flag_thresh
numeric, the ratio threshold for flagging contaminants. If the median of blanks > flag_thresh * median of biological samples, the feature gets flagged.
- flag_label
character, the label used when flagging contaminants. Can be changed if sample processing contaminants and carryover contaminants are flagged separately.
- assay.type
character, assay to be used in case of multiple assays
Examples
data(example_set)
# Make a blank sample which has one (first) feature exceeding the threshold
## Abundance matrix
med <- median(assay(example_set)[1, example_set$QC != "QC"])
assay <- matrix(c(med * 0.05 + 1, rep(0, 79)), ncol = 1, nrow = 80,
dimnames = list(NULL, "Demo_51"))
assay <- cbind(assay(example_set), assay)
## Sample metadata
pheno_data <- colData(example_set)[1, ]
rownames(pheno_data) <- "Demo_51"
pheno_data$Sample_ID <- "Demo_51"
pheno_data$Injection_order <- 51
pheno_data[c("Subject_ID", "Group", "QC", "Time")] <- "Blank"
pheno_data <- rbind(colData(example_set), pheno_data)
## Feature metadata
feature_data <- rowData(example_set)
# Construct SummarizedExperiment object with blank sample
ex_set <- SummarizedExperiment(assays = assay,
colData = pheno_data,
rowData = feature_data)
# Flag contaminant(s)
contaminants_flagged <- flag_contaminants(ex_set, blank_col = "QC",
blank_label = "Blank")
#> INFO [2025-06-23 22:36:34]
#> 1% of features flagged as contaminants