diff --git a/R/calcPCBrainAge.R b/R/calcPCBrainAge.R index 60581ae..0ff71a7 100644 --- a/R/calcPCBrainAge.R +++ b/R/calcPCBrainAge.R @@ -35,16 +35,23 @@ calcPCBrainAge <- function(DNAm, pheno = NULL, CpGImputation = NULL){ ################################################### ### Check if all necessary CpGs are in the data ### ################################################### + + # Debug: convert input data to data.frame if it's a matrix + if (is.matrix(DNAm)) { + DNAm <- as.data.frame(DNAm) + message("Input matrix is converted to a data frame.") + } + missingCpGs <- rownames(PCBrainAge_Model$rotation)[!(rownames(PCBrainAge_Model$rotation) %in% colnames(DNAm))] DNAm[,missingCpGs] <- NA if(!is.na(missingCpGs[1])){ #if there are columns of CpGs missing... if(is.null(CpGImputation)){ #...and the user didn't specify a mean CpG vector, use the Hannum 2013 blood mean data data("imputeMissingBrainCpGs") for(i in 1:length(missingCpGs)){ - datMeth[,missingCpGs[i]] <- imputeMissingBrainCpGs[missingCpGs[i]] + DNAm[,missingCpGs[i]] <- imputeMissingBrainCpGs[missingCpGs[i]] }} else{ #...otherwise use the user's mean CpG vector which contains the required CpG values for(i in 1:length(missingCpGs)){ - datMeth[,missingCpGs[i]] <- CpGImputation[missingCpGs[i]] + DNAm[,missingCpGs[i]] <- CpGImputation[missingCpGs[i]] } } } @@ -54,7 +61,7 @@ calcPCBrainAge <- function(DNAm, pheno = NULL, CpGImputation = NULL){ DNAm <- DNAm[,match(rownames(PCBrainAge_Model$rotation), colnames(DNAm))] if(any(is.na(DNAm))){ - DNAm <- apply(DNAm,2,meanimpute) + DNAm <- apply(DNAm,2,meanImpute) # Debug: call the function meanImpute message("Mean imputation successfully completed for missing CpG values") } @@ -73,13 +80,3 @@ calcPCBrainAge <- function(DNAm, pheno = NULL, CpGImputation = NULL){ pheno } } - - - - - - - - - -