Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changed input format #3

Merged
merged 7 commits into from
Aug 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@ Remotes:
Config/testthat/edition: 3
Encoding: UTF-8
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.2.3
RoxygenNote: 7.3.1
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 3 additions & 5 deletions R/FlowSortedBlood.R
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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]
Expand Down
9 changes: 4 additions & 5 deletions R/epidish.R
Original file line number Diff line number Diff line change
@@ -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,...)
Expand Down Expand Up @@ -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]
Expand Down
27 changes: 12 additions & 15 deletions R/main.R
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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(
Expand All @@ -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)){
Expand All @@ -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')

Expand Down
14 changes: 9 additions & 5 deletions R/methylResolver.R
Original file line number Diff line number Diff line change
@@ -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).
Expand All @@ -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,
Expand Down
8 changes: 3 additions & 5 deletions R/methylcc.R
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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,
Expand All @@ -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]
Expand Down
15 changes: 15 additions & 0 deletions R/util.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
#'
Expand Down
14 changes: 14 additions & 0 deletions man/check_input_mset.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 3 additions & 8 deletions man/deconvolute.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 21 additions & 0 deletions man/run_all_methods.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 2 additions & 5 deletions man/run_epidish.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 2 additions & 5 deletions man/run_flowsortedblood.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 2 additions & 5 deletions man/run_methylcc.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 2 additions & 5 deletions man/run_methylresolver.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 4 additions & 8 deletions tests/testthat/test_methods.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
Loading
Loading