R6 class that encapsulates the mlr3 pipeline for biomarker discovery. Guarantees zero data leakage by enforcing all preprocessing, feature selection, and model training within proper cross-validation folds.
Details
OmicPipeline is the central class for OmicSelector. It replaces the legacy script-based approach with a rigorous, composable, and reproducible architecture.
Key features: - All preprocessing (imputation, scaling) occurs inside CV folds - Feature selection is embedded in the inner loop of nested CV - Oversampling (SMOTE/ROSE) is applied only to training data per fold - Factory methods generate configured GraphLearners
Methods
Method new()
Create a new OmicPipeline object
Usage
OmicPipeline$new(
data,
target,
positive = NULL,
patient_id = NULL,
batch = NULL,
id = "omic_task"
)Arguments
dataEither a data.frame or a named list of data.frames for multi-omics. For multi-omics, use named list: list(rna = rna_data, mirna = mirna_data). Features will be namespaced: rna::gene1, mirna::hsa-miR-21.
targetName of the target column
positivePositive class label (for binary classification)
patient_idOptional column name for patient grouping (prevents leakage)
batchOptional column name for batch information
idUnique identifier for this pipeline
Method create_graph_learner()
Create a GraphLearner with proper leakage prevention
Usage
OmicPipeline$create_graph_learner(
filter = "anova",
model = "ranger",
n_features = 20,
impute_method = "median",
scale = TRUE,
oversample = NULL,
screening = FALSE,
screening_nfeat = NULL,
screening_frac = 0.2,
batch_correct = FALSE,
autoencoder = NULL
)Arguments
filterFilter method name (e.g., "anova", "mrmr", "correlation")
modelModel type (e.g., "ranger", "glmnet", "svm", "mlp", "tabtransformer", "fttransformer", "tabnet", "tabm", "catboost", "tabpfn") or an mlr3 Learner object.
n_featuresNumber of features to select (or proportion if < 1)
impute_methodImputation method ("median", "mean", "sample")
scaleLogical, whether to scale features
oversampleOversampling method (NULL, "smote", "rose")
screeningLogical, whether to apply a fast variance-based screening filter before the main selection step (default: FALSE)
screening_nfeatInteger, number of features to keep during screening. If NULL, uses screening_frac.
screening_fracNumeric (0,1], fraction of features to keep during screening when screening_nfeat is NULL (default: 0.2)
batch_correctLogical or character. If TRUE, adds FrozenComBat batch correction using the batch column specified in pipeline creation. If a character string, uses that as the batch column name. Default: FALSE.
autoencoderLogical or list. If TRUE, inserts a torch autoencoder PipeOp after scaling. If a list, its contents are passed to
create_autoencoder_pipeop()to configure latent dimension, training, and transfer options. Default: NULL (disabled).
Method create_auto_fselector()
Create an AutoTuner that tunes filter.nfeat in the inner CV loop
Usage
OmicPipeline$create_auto_fselector(
learner,
filter_values = c(5, 10, 20, 50),
inner_resampling = NULL,
measure = NULL,
tuner = "grid_search"
)Method benchmark()
Run benchmark with proper nested cross-validation
Usage
OmicPipeline$benchmark(
learners,
outer_folds = 5,
inner_folds = 3,
stratify = TRUE,
seed = NULL,
parallel = TRUE,
threads = 1,
cache_dir = NULL,
cache_key = NULL,
screening = FALSE,
screening_nfeat = NULL,
screening_frac = 0.2
)Arguments
learnersList of learners to benchmark
outer_foldsNumber of outer CV folds
inner_foldsNumber of inner CV folds
stratifyLogical, whether to stratify by outcome
seedRandom seed for reproducibility
parallelLogical, whether to run in parallel (default: TRUE)
threadsInteger, number of threads for mlr3 learners (default: 1)
cache_dirOptional directory to cache benchmark results (RDS)
cache_keyOptional cache key override (string)
screeningLogical, apply variance screening before nested CV
screening_nfeatInteger, number of features to keep in screening
screening_fracNumeric (0,1], fraction of features to keep in screening
Method fit()
Fit a learner on the full dataset and return the trained model and selected features (for deployment).
Usage
OmicPipeline$fit(
learner,
seed = NULL,
threads = 1,
screening = FALSE,
screening_nfeat = NULL,
screening_frac = 0.2
)Arguments
learnerA Learner or GraphLearner
seedRandom seed for reproducibility
threadsInteger, number of threads for mlr3 learners (default: 1)
screeningLogical, apply variance screening before selection
screening_nfeatInteger, number of features to keep in screening
screening_fracNumeric (0,1], fraction of features to keep in screening
Method get_modality_info()
Get modality information for multi-omics data
Examples
if (FALSE) { # \dontrun{
# Create pipeline from data
pipeline <- OmicPipeline$new(
data = my_data,
target = "outcome",
positive = "Case"
)
# Create a graph learner with feature selection
learner <- pipeline$create_graph_learner(
filter = "anova",
model = "ranger",
n_features = 20
)
# Run nested cross-validation
result <- pipeline$benchmark(learner, outer_folds = 5, inner_folds = 3)
} # }