diff --git a/DESCRIPTION b/DESCRIPTION index e9ee092..d58995f 100755 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -31,4 +31,4 @@ Remotes: Config/testthat/edition: 3 Encoding: UTF-8 Roxygen: list(markdown = TRUE) -RoxygenNote: 7.2.3 +RoxygenNote: 7.3.1 diff --git a/NAMESPACE b/NAMESPACE index 5fb8ace..796271f 100755 --- a/NAMESPACE +++ b/NAMESPACE @@ -4,6 +4,7 @@ export(compare_results) export(deconvolute) export(deconvolution_methods) export(normalize_deconv_results) +export(run_all_methods) export(run_epidish) export(run_flowsortedblood) export(run_methylcc) diff --git a/R/FlowSortedBlood.R b/R/FlowSortedBlood.R index d2fc05f..47e6e01 100644 --- a/R/FlowSortedBlood.R +++ b/R/FlowSortedBlood.R @@ -1,7 +1,6 @@ #' Run the improved Houseman method #' -#' @param meth methylated data matrix -#' @param unmeth unmethylated data matrix +#' @param methyl_set A minfi MethylSet #' @param array type of methylation array that was used. possible options are '450k' and 'EPIC' #' @param compositeCellType Which composite cell type is being deconvoluted. Should be one of "Blood", "CordBloodCombined", "CordBlood", "CordBloodNorway", "CordTissueAndBlood", or "DLPFC". See details for preferred approaches. #' @param processMethod Joint normalization/background correction for user and reference data. For MethylSet objects only "preprocessQuantile" is available. Set it to any minfi preprocessing function as a character if you want to override it, like "preprocessFunnorm" @@ -21,15 +20,14 @@ #' @export #' #' @examples -run_flowsortedblood <- function(meth, unmeth, array = c('450k','EPIC'), +run_flowsortedblood <- function(methyl_set, array = c('450k','EPIC'), compositeCellType=c('Blood','CordBloodCombined','CordBlood','CordBloodNorway','CordTissueAndBlood','DLPFC'), processMethod = 'preprocessQuantile', probeSelect = c('IDOL','both','any'), cellTypes =c('CD8T','CD4T','NK','Bcell','Mono','Neu'), referencePlatform = c('IlluminaHumanMethylationEPIC','IlluminaHumanMethylation450k','IlluminaHumanMethylation27k'), referenceset = NULL, CustomCpGs = NULL, meanPlot = FALSE, verbose = TRUE, lessThanOne = FALSE, cellCounts = NULL, ...){ require(FlowSorted.Blood.EPIC) - check_input(meth, unmeth) - methyl_set <- minfi::MethylSet(Meth = meth, Unmeth = unmeth) + check_input_mset(methyl_set) if (length(array) > 1) { array <- array[1] diff --git a/R/epidish.R b/R/epidish.R index 2c44349..900e938 100755 --- a/R/epidish.R +++ b/R/epidish.R @@ -1,7 +1,6 @@ #' run EpiDISH #' -#' @param meth methylated data matrix -#' @param unmeth unmethylated data matrix +#' @param methyl_set A minfi MethylSet #' @param mode Choice of a reference-based method ('RPC','CBS','CP') #' @param reference A matrix of reference 'centroids', i.e. representative molecular profiles, #' for a number of cell subtypes. rows label molecular features (e.g. CpGs,...) @@ -39,14 +38,14 @@ #' @export #' #' @examples -run_epidish <- function(meth, unmeth, mode=c('RPC', 'CBS', 'CP'), +run_epidish <- function(methyl_set, mode=c('RPC', 'CBS', 'CP'), reference=c('blood','breast','epithelial'), maxit = 50, nu.v = c(0.25, 0.5, 0.7), constraint = c("inequality", "equality")){ require(EpiDISH) - check_input(meth, unmeth) - beta_matrix <- create_beta(meth, unmeth) + check_input_mset(methyl_set) + beta_matrix <- minfi::getBeta(methyl_set) if (length(mode) > 1) { mode <- mode[1] diff --git a/R/main.R b/R/main.R index 8e3d6cd..02bafd9 100755 --- a/R/main.R +++ b/R/main.R @@ -15,8 +15,7 @@ deconvolution_methods <- c( #' Deconvolution #' -#' @param meth methylated data matrix -#' @param unmeth unmethylated data matrix +#' @param methyl_set A minfi MethylSet #' @param method A string specifying the method. Supported methods are 'epidish', 'flowsorted', 'methylcc', 'methylresolver' #' @param normalize_results Whether the deconvolution results should be normalized. #' Negative values will be put to 0, and the estimates will be normalized to sum to 1. @@ -30,11 +29,9 @@ deconvolution_methods <- c( #' @examples #' #' ex_data <- minfiData::MsetEx -#' meth <- minfi::getMeth(ex_data) -#' unmeth <- minfi::getUnmeth(ex_data) #' -#' result <- deconvolute(meth, unmeth, method='epidish') -deconvolute <- function(meth, unmeth, method=deconvolution_methods, normalize_results = FALSE, ...){ +#' result <- deconvolute(ex_data, method='epidish') +deconvolute <- function(methyl_set, method=deconvolution_methods, normalize_results = FALSE, ...){ if (length(method) > 1) { stop( @@ -51,10 +48,10 @@ deconvolute <- function(meth, unmeth, method=deconvolution_methods, normalize_re result <- switch (method, - epidish = run_epidish(meth, unmeth, ...)$estF, - flowsorted = run_flowsortedblood(meth, unmeth, ...)$prop, - methylcc = run_methylcc(meth, unmeth, ...), - methylresolver = run_methylresolver(meth, unmeth, ...)$result_fractions + epidish = run_epidish(methyl_set, ...)$estF, + flowsorted = run_flowsortedblood(methyl_set, ...)$prop, + methylcc = as.matrix(run_methylcc(methyl_set, ...)), + methylresolver = as.matrix(run_methylresolver(methyl_set, ...)$result_fractions) ) if(!is.null(result)){ @@ -79,12 +76,12 @@ deconvolute <- function(meth, unmeth, method=deconvolution_methods, normalize_re #' @export #' #' @examples -run_all_methods <- function(meth, unmeth, array = c('450k','EPIC')){ +run_all_methods <- function(methyl_set, array = c('450k','EPIC')){ - res_epidish <- run_epidish(meth, unmeth) - res_flowsorted <- run_flowsortedblood(meth, unmeth, array = array) - res_methylcc <- run_methylcc(meth, unmeth, array = array) - res_methylresolver <- run_methylresolver(meth, unmeth) + res_epidish <- run_epidish(methyl_set) + res_flowsorted <- run_flowsortedblood(methyl_set, array = array) + res_methylcc <- run_methylcc(methyl_set, array = array) + res_methylresolver <- run_methylresolver(methyl_set) results <- list(res_epidish$estF, res_flowsorted$prop, res_methylcc, res_methylresolver$result_fractions) names(results) <- c('EpiDISH','FlowSorted','MethylCC','MethylResolver') diff --git a/R/methylResolver.R b/R/methylResolver.R index 21174b3..76e5336 100644 --- a/R/methylResolver.R +++ b/R/methylResolver.R @@ -1,7 +1,6 @@ #' Run MethylResolver #' -#' @param meth methylated data matrix -#' @param unmeth unmethylated data matrix +#' @param methyl_set A minfi MethylSet #' @param doPar Whether to use parallel processing to speed up the deconvolution computation if many samples are present. Default is FALSE. #' @param numCores Number of cores used for parallel processing to speed up the deconvolution of many samples. Requires doPar = TRUE. Default is 1. numCores = "auto" is max number of cores available minus one. #' @param alpha Set the alpha parameter for LTS deconvolution. This is the fraction of optimal CpGs from the signature matrix which are used for deconvolution. Must be between 0 and 1. Users can specify a vector or a single number. If a vector is specified, a grid search of the values is conducted and the alpha value that results in the lowest RMSE between the original and reconstructed mixture is selected. Default is seq(0.5,0.9,by = 0.05). @@ -13,15 +12,20 @@ #' @export #' #' @examples -run_methylresolver <- function(meth, unmeth, doPar = F, numCores = 1, alpha = seq(0.5,0.9,by = 0.05), +run_methylresolver <- function(methyl_set, doPar = F, numCores = 1, alpha = seq(0.5,0.9,by = 0.05), absolute = TRUE, purityModel = MethylResolver::RFmodel, seed = 1){ require(MethylResolver) set.seed(seed) - check_input(meth, unmeth) - beta_matrix <- create_beta(meth, unmeth) + check_input_mset(methyl_set) + beta_matrix <- minfi::getBeta(methyl_set) + + if (length(alpha) > 1){ + warning("MethylResolver may fail if multiple alpha values are provided. If this occurs, specify a single alpha value between 0.5 and 1.", + immediate. = TRUE) + } result_methylresolver <- MethylResolver::MethylResolver(methylMix = beta_matrix, methylSig = MethylResolver::MethylSig, diff --git a/R/methylcc.R b/R/methylcc.R index a6a7a5c..27d97cb 100755 --- a/R/methylcc.R +++ b/R/methylcc.R @@ -1,7 +1,6 @@ #' run methylCC deconvolution #' -#' @param meth methylated data matrix -#' @param unmeth unmethylated data matrix +#' @param methyl_set A minfi MethylSet #' @param array type of methylation array that was used. possible options are '450k' and 'EPIC' #' @param find_dmrs_object If the user would like to supply different differentially methylated regions, they can use the output from the find_dmrs function to supply different regions to estimatecc. #' @param verbose TRUE/FALSE argument specifying if verbose messages should be returned or not. Default is TRUE. @@ -23,7 +22,7 @@ #' @export #' #' @examples -run_methylcc <- function(meth, unmeth, array = c('450k','EPIC'), +run_methylcc <- function(methyl_set, array = c('450k','EPIC'), find_dmrs_object = NULL, verbose = TRUE, epsilon = 0.01, max_iter = 100, take_intersection = FALSE, include_cpgs = FALSE, include_dmrs = TRUE, @@ -37,8 +36,7 @@ run_methylcc <- function(meth, unmeth, array = c('450k','EPIC'), set.seed(seed) - check_input(meth, unmeth) - methyl_set <- minfi::MethylSet(Meth = meth, Unmeth = unmeth) + check_input_mset(methyl_set) if (length(array) > 1) { array <- array[1] diff --git a/R/util.R b/R/util.R index 1ab7eef..582c027 100644 --- a/R/util.R +++ b/R/util.R @@ -17,6 +17,21 @@ check_input <- function(meth, unmeth){ } } +#' Check input methylSet +#' +#' @param methyl_set +#' +#' +#' @examples +check_input_mset <- function(methyl_set){ + if(!is(methyl_set, "MethylSet")){ + stop('Input is not a MethylSet, stopping.') + } + if(all(is.na(methyl_set))){ + stop('All entries in the MethylSet are NA, stopping.') + } +} + #' Create beta matrix from meth and unmeth matrices #' diff --git a/man/check_input_mset.Rd b/man/check_input_mset.Rd new file mode 100644 index 0000000..6648540 --- /dev/null +++ b/man/check_input_mset.Rd @@ -0,0 +1,14 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/util.R +\name{check_input_mset} +\alias{check_input_mset} +\title{Check input methylSet} +\usage{ +check_input_mset(methyl_set) +} +\arguments{ +\item{methyl_set}{} +} +\description{ +Check input methylSet +} diff --git a/man/deconvolute.Rd b/man/deconvolute.Rd index 44df836..82fccde 100644 --- a/man/deconvolute.Rd +++ b/man/deconvolute.Rd @@ -5,17 +5,14 @@ \title{Deconvolution} \usage{ deconvolute( - meth, - unmeth, + methyl_set, method = deconvolution_methods, normalize_results = FALSE, ... ) } \arguments{ -\item{meth}{methylated data matrix} - -\item{unmeth}{unmethylated data matrix} +\item{methyl_set}{A minfi MethylSet} \item{method}{A string specifying the method. Supported methods are 'epidish', 'flowsorted', 'methylcc', 'methylresolver'} @@ -35,8 +32,6 @@ Deconvolution \examples{ ex_data <- minfiData::MsetEx -meth <- minfi::getMeth(ex_data) -unmeth <- minfi::getUnmeth(ex_data) -result <- deconvolute(meth, unmeth, method='epidish') +result <- deconvolute(ex_data, method='epidish') } diff --git a/man/run_all_methods.Rd b/man/run_all_methods.Rd new file mode 100644 index 0000000..598f03f --- /dev/null +++ b/man/run_all_methods.Rd @@ -0,0 +1,21 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/main.R +\name{run_all_methods} +\alias{run_all_methods} +\title{Run all available deconvolution methods} +\usage{ +run_all_methods(methyl_set, array = c("450k", "EPIC")) +} +\arguments{ +\item{array}{type of methylation array that was used. possible options are '450k' and 'EPIC'} + +\item{meth}{methylated data matrix} + +\item{unmeth}{unmethylated data matrix} +} +\value{ +dataframe with results of all methods +} +\description{ +Run all available deconvolution methods +} diff --git a/man/run_epidish.Rd b/man/run_epidish.Rd index 0b3b757..073c30f 100755 --- a/man/run_epidish.Rd +++ b/man/run_epidish.Rd @@ -5,8 +5,7 @@ \title{run EpiDISH} \usage{ run_epidish( - meth, - unmeth, + methyl_set, mode = c("RPC", "CBS", "CP"), reference = c("blood", "breast", "epithelial"), maxit = 50, @@ -15,9 +14,7 @@ run_epidish( ) } \arguments{ -\item{meth}{methylated data matrix} - -\item{unmeth}{unmethylated data matrix} +\item{methyl_set}{A minfi MethylSet} \item{mode}{Choice of a reference-based method ('RPC','CBS','CP')} diff --git a/man/run_flowsortedblood.Rd b/man/run_flowsortedblood.Rd index bc2cc4f..b02ddf7 100644 --- a/man/run_flowsortedblood.Rd +++ b/man/run_flowsortedblood.Rd @@ -5,8 +5,7 @@ \title{Run the improved Houseman method} \usage{ run_flowsortedblood( - meth, - unmeth, + methyl_set, array = c("450k", "EPIC"), compositeCellType = c("Blood", "CordBloodCombined", "CordBlood", "CordBloodNorway", "CordTissueAndBlood", "DLPFC"), @@ -25,9 +24,7 @@ run_flowsortedblood( ) } \arguments{ -\item{meth}{methylated data matrix} - -\item{unmeth}{unmethylated data matrix} +\item{methyl_set}{A minfi MethylSet} \item{array}{type of methylation array that was used. possible options are '450k' and 'EPIC'} diff --git a/man/run_methylcc.Rd b/man/run_methylcc.Rd index 98f5bea..579dd8e 100755 --- a/man/run_methylcc.Rd +++ b/man/run_methylcc.Rd @@ -5,8 +5,7 @@ \title{run methylCC deconvolution} \usage{ run_methylcc( - meth, - unmeth, + methyl_set, array = c("450k", "EPIC"), find_dmrs_object = NULL, verbose = TRUE, @@ -26,9 +25,7 @@ run_methylcc( ) } \arguments{ -\item{meth}{methylated data matrix} - -\item{unmeth}{unmethylated data matrix} +\item{methyl_set}{A minfi MethylSet} \item{array}{type of methylation array that was used. possible options are '450k' and 'EPIC'} diff --git a/man/run_methylresolver.Rd b/man/run_methylresolver.Rd index be74c0b..0529f97 100644 --- a/man/run_methylresolver.Rd +++ b/man/run_methylresolver.Rd @@ -5,8 +5,7 @@ \title{Run MethylResolver} \usage{ run_methylresolver( - meth, - unmeth, + methyl_set, doPar = F, numCores = 1, alpha = seq(0.5, 0.9, by = 0.05), @@ -16,9 +15,7 @@ run_methylresolver( ) } \arguments{ -\item{meth}{methylated data matrix} - -\item{unmeth}{unmethylated data matrix} +\item{methyl_set}{A minfi MethylSet} \item{doPar}{Whether to use parallel processing to speed up the deconvolution computation if many samples are present. Default is FALSE.} diff --git a/tests/testthat/test_methods.R b/tests/testthat/test_methods.R index 1abf40b..e130113 100644 --- a/tests/testthat/test_methods.R +++ b/tests/testthat/test_methods.R @@ -9,8 +9,7 @@ unmeth <- minfi::getUnmeth(ex_data) # write.csv() test_that("EpiDISH works", { - epidish_res <- methylDeconv::run_epidish(meth = meth, - unmeth = unmeth)$estF + epidish_res <- methylDeconv::run_epidish(methyl_set = ex_data)$estF check_result <- as.matrix(read.csv("test_results/epidish.csv", row.names = 1, check.names = FALSE @@ -23,8 +22,7 @@ test_that("EpiDISH works", { test_that("methylCC works", { - methylcc_res <- as.matrix(methylDeconv::run_methylcc(meth = meth, - unmeth = unmeth)) + methylcc_res <- as.matrix(methylDeconv::run_methylcc(methyl_set = ex_data)) check_result <- as.matrix(read.csv("test_results/methylcc.csv", row.names = 1, check.names = FALSE @@ -36,8 +34,7 @@ test_that("methylCC works", { }) test_that("FlowSorted works", { - flowSorted_res <- methylDeconv::run_flowsortedblood(meth = meth, - unmeth = unmeth)$prop + flowSorted_res <- methylDeconv::run_flowsortedblood(methyl_set = ex_data)$prop check_result <- as.matrix(read.csv("test_results/flowsorted.csv", row.names = 1, check.names = FALSE @@ -49,8 +46,7 @@ test_that("FlowSorted works", { }) test_that("MethylResolver works", { - methylResolver_res <- methylDeconv::run_methylresolver(meth = meth, - unmeth = unmeth)$result_fractions + methylResolver_res <- as.matrix(methylDeconv::run_methylresolver(methyl_set = ex_data, alpha = 1)$result_fractions) check_result <- as.matrix(read.csv("test_results/methylresolver.csv", row.names = 1, check.names = FALSE diff --git a/tests/testthat/test_results/methylresolver.csv b/tests/testthat/test_results/methylresolver.csv index 7e52d72..81a9eee 100644 --- a/tests/testthat/test_results/methylresolver.csv +++ b/tests/testthat/test_results/methylresolver.csv @@ -1,7 +1,7 @@ "","Mon","Dendritic","Macro","Neu","Eos","Treg","Tnaive","Tmem","CD8","NK","Bcell" -"5723646052_R02C02",0.219771092951667,0.0861319199283645,0.0596498819365518,0,0.0725426431324884,0.347881656378013,0,0.0746465804394808,0,0.029726311276478,0.109649913956957 -"5723646052_R04C01",0.0971267523521064,0.239835821095724,0,0,0.132294731613037,0.264211483611564,0,0.0926162665188302,0,0.0650577438496565,0.108857200959082 -"5723646052_R05C02",0.559585485581137,0.0105125692665089,0.083076249067634,0,0.0812112234247883,0.218846225862262,0,0.0433043896758658,0,0.00346385712180442,0 -"5723646053_R04C02",0,0.842753507146925,0,0,0.0515323863024912,0.10511336459255,0,0,0,0.000600741958034185,0 -"5723646053_R05C02",0.140500582258948,0.265437786277607,0,0,0.0478168002499539,0.458540645948786,0,0,0,0.049024324663619,0.0386798606010854 -"5723646053_R06C02",0.363218585487635,0,0,0,0.117639727294471,0.444965694630154,0,0.0173668383027685,0,0.0568091542849726,0 +"5723646052_R02C02",0.167203065138497,0.145486524197985,0.0608912926256056,0,0.0709494473420341,0.340587843459731,0,0.0654762699661238,0,0.0287797017007188,0.120625855569304 +"5723646052_R04C01",0.132383833335766,0.182218808186763,0,0,0.108998875203547,0.327310484555183,0,0.0589651145844965,0,0.0704309435372101,0.119691940597035 +"5723646052_R05C02",0.241826756981773,0.0167468426276328,0.226240794248074,0,0.0996021334516035,0.358153608393456,0,0,0,0.055656843013556,0.00177302128390493 +"5723646053_R04C02",0.186875544282466,0.11223992371781,0.166764265495769,0,0.0963338930124932,0.370548610305323,0,0.0128974226831663,0,0.0279980247366601,0.0263423157663124 +"5723646053_R05C02",0.25312660036903,0.131897038080877,0,0,0.065120037500709,0.37231139220221,0,0.0288506617808647,0,0.0676917949054884,0.0810024751608202 +"5723646053_R06C02",0.283962927385346,0.106388787727763,0,0.00506913332729203,0.103074464035677,0.430263773002906,0,0,0,0.0712409145210166,0