| Title: | DNA methylation-based machine learning models |
|---|---|
| Description: | This package provides model data and functions for easily using machine learning models that use data from the DNA methylome to classify cancer type and phenotype from a sample. The primary motivation for the development of this package is to abstract away the granular and accessibility-limiting code required to utilize machine learning models in R. Our package provides this abstraction for RandomForest, e1071 Support Vector, Extreme Gradient Boosting, and Tensorflow models. This is paired with an ExperimentHub component, which contains models developed for epigenetic cancer classification and predicting phenotypes. This includes CNS tumor classification, Pan-cancer classification, race prediction, cell of origin classification, and subtype classification models. The package links to our models on ExperimentHub. The package currently supports HM450, EPIC, EPICv2, MSA, and MM285. |
| Authors: | Wanding Zhou [aut] (ORCID: <https://orcid.org/0000-0001-9126-1932>), Jacob Fanale [aut, cre] (ORCID: <https://orcid.org/0009-0002-0490-3269>) |
| Maintainer: | Jacob Fanale <[email protected]> |
| License: | Artistic-2.0 |
| Version: | 1.8.0 |
| Built: | 2026-10-10 11:18:27 UTC |
| Source: | https://github.com/bioc/CytoMethIC |
Internal function for fraction optimization
.optimizeFrac( frac, ref, q, errFunc, temp = 0.5, maxIter = 1000, delta = 1e-04, step.max = 1, verbose = FALSE ).optimizeFrac( frac, ref, q, errFunc, temp = 0.5, maxIter = 1000, delta = 1e-04, step.max = 1, verbose = FALSE )
frac |
initial fraction |
ref |
reference |
q |
query |
errFunc |
error function |
temp |
annealing temperature |
maxIter |
maximum iteration to stop after converge |
delta |
delta score to reset counter |
step.max |
maximum step, do not adjust |
verbose |
output debug info |
a list of fractions and min err
print package verison of cytomethic and depended packages to help troubleshoot installation issues.
cmi_checkVersion()cmi_checkVersion()
print the versions of cytomethic and dependencies
cmi_checkVersion()cmi_checkVersion()
This is a reference-based cell composition estimation. The function takes a reference methylation status matrix (rows for probes and columns for cell types) and a query beta value measurement.
cmi_deconvolution(ref, q, trim = FALSE, ...)cmi_deconvolution(ref, q, trim = FALSE, ...)
ref |
reference methylation |
q |
target measurement: length(q) == nrow(ref) |
trim |
to trim query input beta values. this relieves unclean background subtraction |
... |
extra parameters for optimization. |
The length of the target beta values should be the same as the number of rows of the reference Matrix. The function outputs a list containing the estimated cell fraction, the error of optimization.
a list of fraction, min error.
ref = cbind( CD4 = c(1,1,1,0,1,0), CD19 = c(0,0,1,1,0,1), CD14 = c(1,1,1,1,0,1)) rownames(ref) = paste0("cg",1:6) trueFrac = runif(3) trueFrac = trueFrac / sum(trueFrac) q = ref %*% trueFrac trueFrac cmi_deconvolution(ref, q)ref = cbind( CD4 = c(1,1,1,0,1,0), CD19 = c(0,0,1,1,0,1), CD14 = c(1,1,1,1,0,1)) rownames(ref) = paste0("cg",1:6) trueFrac = runif(3) trueFrac = trueFrac / sum(trueFrac) q = ref %*% trueFrac trueFrac cmi_deconvolution(ref, q)
This is a reference-based cell composition estimation. The function takes a reference methylation status matrix (rows for probes and columns for cell types) and a query beta value measurement.
cmi_deconvolution2(ref, q, trim = FALSE, ...)cmi_deconvolution2(ref, q, trim = FALSE, ...)
ref |
reference methylation |
q |
target measurement: length(q) == nrow(ref) |
trim |
to trim query input beta values. this relieves unclean background subtraction |
... |
extra parameters to .optimizeFrac |
The length of the target beta values should be the same as the number of rows of the reference Matrix. The method assumes one unknown component. It outputs a list containing the estimated cell fraction, the error of optimization and methylation status of the unknown component.
a list of fraction, min error and unknown component methylation state
ref = cbind( CD4 = c(1,1,1,0,1,0), CD19 = c(0,0,1,1,0,1), CD14 = c(1,1,1,1,0,1)) rownames(ref) = paste0("cg",1:6) trueFrac = runif(4) trueFrac = trueFrac / sum(trueFrac) ref_unk = sample(c(0,1), nrow(ref), replace=TRUE) q = cbind(ref_unk, ref) %*% trueFrac trueFrac res = cmi_deconvolution2(ref, q) res$fracref = cbind( CD4 = c(1,1,1,0,1,0), CD19 = c(0,0,1,1,0,1), CD14 = c(1,1,1,1,0,1)) rownames(ref) = paste0("cg",1:6) trueFrac = runif(4) trueFrac = trueFrac / sum(trueFrac) ref_unk = sample(c(0,1), nrow(ref), replace=TRUE) q = cbind(ref_unk, ref) %*% trueFrac trueFrac res = cmi_deconvolution2(ref, q) res$frac
This is an internal object which will be updated on every new release
tibble
master sheet of CytoMethIC model objects
print(cmi_models[,c("EHID","Title")])print(cmi_models[,c("EHID","Title")])
The cmi_predict function takes in a model and a sample, and uses the model to predict it. This function supports randomForest, e1071::svm, xgboost, and keras/tensorflow models. For xgboost and keras models, the features used in classification as well as a label mapping must be provided for output.
cmi_predict(betas, cmi_model, verbose = FALSE, BPPARAM = SerialParam())cmi_predict(betas, cmi_model, verbose = FALSE, BPPARAM = SerialParam())
betas |
DNA methylation beta |
cmi_model |
Cytomethic model downloaded from ExperimentHub |
verbose |
be verbose with warning |
BPPARAM |
use MulticoreParam(n) for parallel processing |
predicted cancer type label
library(sesame) library(ExperimentHub) library(CytoMethIC) ## Cancer Type model = ExperimentHub()[["EH8395"]] betas = openSesame(sesameDataGet("EPICv2.8.SigDF")[[1]]) betas = imputeBetas(mLiftOver(betas, "HM450")) cmi_predict(betas, model) betas = openSesame(sesameDataGet('EPIC.1.SigDF'), mask=FALSE) cmi_predict(betas, model) betas = sesameDataGet("HM450.1.TCGA.PAAD")$betas betas = imputeBetas(betas) cmi_predict(betas, model)library(sesame) library(ExperimentHub) library(CytoMethIC) ## Cancer Type model = ExperimentHub()[["EH8395"]] betas = openSesame(sesameDataGet("EPICv2.8.SigDF")[[1]]) betas = imputeBetas(mLiftOver(betas, "HM450")) cmi_predict(betas, model) betas = openSesame(sesameDataGet('EPIC.1.SigDF'), mask=FALSE) cmi_predict(betas, model) betas = sesameDataGet("HM450.1.TCGA.PAAD")$betas betas = imputeBetas(betas) cmi_predict(betas, model)