Overview
This vignette demonstrates a full deep learning workflow with OmicSelector, including autoencoder feature compression, mlr3torch training, checkpoint export/import, and fine‑tuning.
Requirements: - torch -
mlr3torch
install.packages("torch")
torch::install_torch()
install.packages("mlr3torch")Load Package and Data
library(OmicSelector)
data("original_TCGA_data", package = "OmicSelector")Prepare a Small TCGA Subset
feature_cols <- grep("^hsa\\.", names(original_TCGA_data), value = TRUE)
feature_cols <- head(feature_cols, 300)
subset_df <- original_TCGA_data[, c("patient", "sample_type", feature_cols), drop = FALSE]
subset_df <- as.data.frame(subset_df)
subset_df$sample_type <- factor(subset_df$sample_type)
set.seed(1)
idx_tumor <- which(subset_df$sample_type == "PrimaryTumor")
idx_normal <- which(subset_df$sample_type == "SolidTissueNormal")
subset_df <- subset_df[c(sample(idx_tumor, 60), sample(idx_normal, 60)), ]
subset_df <- subset_df[sample(nrow(subset_df)), ]Create Pipeline
pipeline <- OmicPipeline$new(
data = subset_df,
target = "sample_type",
positive = "PrimaryTumor",
patient_id = "patient"
)Build Deep Learning GraphLearner
This pipeline adds a torch autoencoder before feature selection and trains an MLP via mlr3torch.
Run Nested CV
result <- pipeline$benchmark(
learners = learner,
outer_folds = 3,
inner_folds = 2,
seed = 42,
parallel = TRUE,
threads = 1
)
print(result)Export / Import Checkpoint
export_omicfit_checkpoint(fit, "mlp_checkpoint.pt")
# Load into a trained learner (for inference)
fit <- import_omicfit_checkpoint(fit, "mlp_checkpoint.pt")Fine‑tune on a New Task
task <- pipeline$get_task()
finetuned <- finetune_mlr3torch_checkpoint(
learner = learner,
task = task,
path = "mlp_checkpoint.pt",
epochs = 30
)
# Or stay at the OmicFit level
finetuned_fit <- finetune_omicfit_checkpoint(
fit = fit,
task = task,
path = "mlp_checkpoint.pt",
epochs = 30
)Notes
- Autoencoders can also be trained separately via
autoencoder_fit()and passed into the pipeline usingpretrainedandfreeze_encoder. - For transfer learning across datasets, export checkpoints and
re‑train with
finetune_mlr3torch_checkpoint().