diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000..7d03d80 Binary files /dev/null and b/.DS_Store differ diff --git a/.Rbuildignore b/.Rbuildignore new file mode 100644 index 0000000..91114bf --- /dev/null +++ b/.Rbuildignore @@ -0,0 +1,2 @@ +^.*\.Rproj$ +^\.Rproj\.user$ diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..5b6a065 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +.Rproj.user +.Rhistory +.RData +.Ruserdata diff --git a/DESCRIPTION b/DESCRIPTION index d869ba5..35d120e 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -9,7 +9,7 @@ Description: Code to easily calculate nearly all of the CpG-based epigenetic clo License: What license is it under? Encoding: UTF-8 LazyData: true -RoxygenNote: 7.2.0 +RoxygenNote: 7.3.2 Imports: readr, dplyr, diff --git a/NAMESPACE b/NAMESPACE index 1860ec0..f474b3d 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -16,6 +16,8 @@ export(calcDunedinPoAm38) export(calcEpiTOC) export(calcEpiTOC2) export(calcGaragnani) +export(calcGrimAgeV1) +export(calcGrimAgeV2) export(calcHRSInChPhenoAge) export(calcHannum) export(calcHorvath1) @@ -28,6 +30,7 @@ export(calcLeeRobust) export(calcLin) export(calcMayne) export(calcMiAge) +export(calcPCClocks) export(calcPEDBE) export(calcPhenoAge) export(calcSmokingMcCartney) diff --git a/R/.DS_Store b/R/.DS_Store new file mode 100644 index 0000000..5008ddf Binary files /dev/null and b/R/.DS_Store differ diff --git a/R/calcAlcoholMcCartney.R b/R/calcAlcoholMcCartney.R index 0190d08..8cb873c 100644 --- a/R/calcAlcoholMcCartney.R +++ b/R/calcAlcoholMcCartney.R @@ -10,8 +10,8 @@ #' @return If you added the optional pheno input (preferred) the function appends a column with the clock calculation and returns the dataframe. Otherwise, it will return a vector of calculated clock values in order of the #' @export #' -#' @examples calcAlcoholMcCartney(exampleBetas, examplePheno, imputation = F) -calcAlcoholMcCartney <- function(DNAm, pheno = NULL, CpGImputation = NULL, imputation = F){ +#' @examples calcAlcoholMcCartney(exampleBetas, examplePheno, imputation = T) +calcAlcoholMcCartney <- function(DNAm, pheno = NULL, CpGImputation = NULL, imputation = T){ ####################### ### Read in the Data### diff --git a/R/calcBMIMcCartney.R b/R/calcBMIMcCartney.R index 7ae70f4..3787f1e 100644 --- a/R/calcBMIMcCartney.R +++ b/R/calcBMIMcCartney.R @@ -10,8 +10,8 @@ #' @return If you added the optional pheno input (preferred) the function appends a column with the clock calculation and returns the dataframe. Otherwise, it will return a vector of calculated clock values in order of the #' @export #' -#' @examples calcBMIMcCartney(exampleBetas, examplePheno, imputation = F) -calcBMIMcCartney <- function(DNAm, pheno = NULL, CpGImputation = NULL, imputation = F){ +#' @examples calcBMIMcCartney(exampleBetas, examplePheno, imputation = T) +calcBMIMcCartney <- function(DNAm, pheno = NULL, CpGImputation = NULL, imputation = T){ ####################### ### Read in the Data### diff --git a/R/calcBocklandt.R b/R/calcBocklandt.R index e6bb984..3abb140 100644 --- a/R/calcBocklandt.R +++ b/R/calcBocklandt.R @@ -10,8 +10,8 @@ #' @return If you added the optional pheno input (preferred) the function appends a column with the clock calculation and returns the dataframe. Otherwise, it will return a vector of calculated clock values in order of the #' @export #' -#' @examples calcBocklandt(exampleBetas, examplePheno, imputation = F) -calcBocklandt <- function(DNAm, pheno = NULL, CpGImputation = NULL, imputation = F){ +#' @examples calcBocklandt(exampleBetas, examplePheno, imputation = T) +calcBocklandt <- function(DNAm, pheno = NULL, CpGImputation = NULL, imputation = T){ ####################### ### Read in the Data### diff --git a/R/calcBohlin.R b/R/calcBohlin.R index c8d36fd..66f8ed5 100644 --- a/R/calcBohlin.R +++ b/R/calcBohlin.R @@ -10,8 +10,8 @@ #' @return If you added the optional pheno input (preferred) the function appends a column with the clock calculation and returns the dataframe. Otherwise, it will return a vector of calculated clock values in order of the #' @export #' -#' @examples calcBohlin(exampleBetas, examplePheno, imputation = F) -calcBohlin <- function(DNAm, pheno = NULL, CpGImputation = NULL, imputation = F){ +#' @examples calcBohlin(exampleBetas, examplePheno, imputation = T) +calcBohlin <- function(DNAm, pheno = NULL, CpGImputation = NULL, imputation = T){ ####################### ### Read in the Data### diff --git a/R/calcClockCategory.R b/R/calcClockCategory.R index 5e19c4b..d02bc58 100644 --- a/R/calcClockCategory.R +++ b/R/calcClockCategory.R @@ -12,9 +12,9 @@ #' @return A dataframe that has column names of the core clocks giving you multiple clocks at once in an easy to compute function. These will be appended onto the existing pheno dataframe as defined in the inputs. #' @export #' -#' @examples calcClockCategory(exampleBetas, examplePheno, category = "chronological", imputation = F) +#' @examples calcClockCategory(exampleBetas, examplePheno, category = "chronological", imputation = T) calcClockCategory <- function(DNAm, pheno , category = NULL, - CpGImputation = NULL, imputation = F){ + CpGImputation = NULL, imputation = T){ message("Please remember to cite all of the clocks you have used! Please refer to the README.md file for assistance.") diff --git a/R/calcCoreClocks.R b/R/calcCoreClocks.R index 448bcdd..e121d3a 100644 --- a/R/calcCoreClocks.R +++ b/R/calcCoreClocks.R @@ -10,8 +10,8 @@ #' @return A dataframe that has column names of the core clocks giving you multiple clocks at once in an easy to compute function. These will be appended onto the existing pheno dataframe as defined in the inputs. #' @export #' -#' @examples calcCoreClocks(exampleBetas, examplePheno, imputation = F) -calcCoreClocks <- function(DNAm, pheno , CpGImputation = NULL, imputation = F){ +#' @examples calcCoreClocks(exampleBetas, examplePheno, imputation = T) +calcCoreClocks <- function(DNAm, pheno , CpGImputation = NULL, imputation = T){ message("Please remember to cite the core Clocks you have used! Please refer to the README.md file for assistance.") diff --git a/R/calcDNAmClockCortical.R b/R/calcDNAmClockCortical.R index 5600f18..f39a9da 100644 --- a/R/calcDNAmClockCortical.R +++ b/R/calcDNAmClockCortical.R @@ -10,9 +10,9 @@ #' @return If you added the optional pheno input (preferred) the function appends a column with the clock calculation and returns the dataframe. Otherwise, it will return a vector of calculated clock values in order of the #' @export #' -#' @examples calcDNAmClockCortical(exampleBetas, examplePheno, imputation = F) +#' @examples calcDNAmClockCortical(exampleBetas, examplePheno, imputation = T) #' @examples calcDNAmClockCortical(exampleBetas, examplePheno, CpGImputation = DNAmClockCortical_imputeRef, imputation = T) # Imputation in the case that there are missing CpGs using the original Brain Imputation from authors -calcDNAmClockCortical <- function(DNAm, pheno = NULL, CpGImputation = NULL, imputation = F){ +calcDNAmClockCortical <- function(DNAm, pheno = NULL, CpGImputation = NULL, imputation = T){ ################################################### ### Check if all necessary CpGs are in the data ### diff --git a/R/calcDNAmTL.R b/R/calcDNAmTL.R index 5f65198..511e0dc 100644 --- a/R/calcDNAmTL.R +++ b/R/calcDNAmTL.R @@ -10,8 +10,8 @@ #' @return If you added the optional pheno input (preferred) the function appends a column with the clock calculation and returns the dataframe. Otherwise, it will return a vector of calculated clock values in order of the #' @export #' -#' @examples calcDNAmTL(exampleBetas, examplePheno, imputation = F) -calcDNAmTL <- function(DNAm, pheno = NULL, CpGImputation = NULL, imputation = F){ +#' @examples calcDNAmTL(exampleBetas, examplePheno, imputation = T) +calcDNAmTL <- function(DNAm, pheno = NULL, CpGImputation = NULL, imputation = T){ ####################### ### Read in the Data### diff --git a/R/calcDunedinPoAm38.R b/R/calcDunedinPoAm38.R index d918511..b74e9f3 100644 --- a/R/calcDunedinPoAm38.R +++ b/R/calcDunedinPoAm38.R @@ -11,7 +11,7 @@ #' @export #' @source #' -#' @examples calcDunedinPoAm38(exampleBetas, examplePheno, imputation = F) +#' @examples calcDunedinPoAm38(exampleBetas, examplePheno, imputation = T) calcDunedinPoAm38 <- function(DNAm, pheno = NULL, CpGImputation = NULL, imputation = T){ ########################### diff --git a/R/calcEpiTOC.R b/R/calcEpiTOC.R index 299e182..c848b9b 100644 --- a/R/calcEpiTOC.R +++ b/R/calcEpiTOC.R @@ -11,7 +11,7 @@ #' @export #' @source #' -#' @examples calcEpiTOC(exampleBetas, examplePheno, imputation = F) +#' @examples calcEpiTOC(exampleBetas, examplePheno, imputation = T) calcEpiTOC <- function(DNAm, pheno = NULL, CpGImputation = NULL, imputation = T){ ####################### diff --git a/R/calcEpiTOC2.R b/R/calcEpiTOC2.R index 5e6cd67..2a32549 100644 --- a/R/calcEpiTOC2.R +++ b/R/calcEpiTOC2.R @@ -11,7 +11,7 @@ #' @export #' @source #' -#' @examples calcEpiTOC2(exampleBetas, examplePheno, imputation = F) +#' @examples calcEpiTOC2(exampleBetas, examplePheno, imputation = T) calcEpiTOC2 <- function(DNAm, pheno = NULL, CpGImputation = NULL, imputation = T, approximated = F){ ####################### diff --git a/R/calcGaragnani.R b/R/calcGaragnani.R index 260db06..e796821 100644 --- a/R/calcGaragnani.R +++ b/R/calcGaragnani.R @@ -10,8 +10,8 @@ #' @return If you added the optional pheno input (preferred) the function appends a column with the clock calculation and returns the dataframe. Otherwise, it will return a vector of calculated clock values in order of the #' @export #' -#' @examples calcGaragnani(exampleBetas, examplePheno, imputation = F) -calcGaragnani <- function(DNAm, pheno = NULL, CpGImputation = NULL, imputation = F){ +#' @examples calcGaragnani(exampleBetas, examplePheno, imputation = T) +calcGaragnani <- function(DNAm, pheno = NULL, CpGImputation = NULL, imputation = T){ ####################### ### Read in the Data### diff --git a/R/calcGrimAgeV1.R b/R/calcGrimAgeV1.R new file mode 100644 index 0000000..4c228ce --- /dev/null +++ b/R/calcGrimAgeV1.R @@ -0,0 +1,91 @@ +#' CalcGrimAgeV1 +#' +#' @description A function to calculate GrimAgeV1 +#' +#' @param DNAm a matrix of methylation beta values. Needs to be rows = samples and columns = CpGs, with rownames and colnames. +#' @param pheno Optional: The sample phenotype data (also with samples as rows) that the clock will be appended to. +#' @param CpGImputation An optional namesd vector for the mean value of each CpG that will be input from another dataset if such values are missing here (from sample cleaning) +#' @param imputation Logical value that will allows you to perform (T)/ skip (F) imputation of mean values for missing CpGs. Warning: when imputation = F if there are missing CpGs, it will automatically ignore these CpGs during calculation, making the clock values less accurate. +#' +#' @return If you added the optional pheno input (preferred) the function appends a column with the clock calculation and returns the dataframe. Otherwise, it will return a vector of calculated clock values in order of the +#' @export +#' +#' @examples CalcGrimAgeV1(exampleBetas, examplePheno, imputation = F) +#' +#' +#' +#' +#' + + +calcGrimAgeV1 <- function(datMeth, datPheno){ + + if(!("Age" %in% variable.names(datPheno))){ + stop("Error: datPheno must have a column named Age") + } + if(!("Female" %in% variable.names(datPheno))){ + stop("Error: datPheno must have a column named Female") + } + if(sum(startsWith(colnames(datMeth),"cg")) == 0){ + warning("Warning: It looks like you may need to format datMeth using t(datMeth) to get samples as rows!") + } + + #In datPheno, rows are samples and columns are phenotypic variables. + #One of the phenotypic variables must be "Age", and another one "Female" (coded as Female = 1, Male = 0; should be a numeric variable as this will be included in PCGrimAge calculation) + #Also ensure that the order of datMeth sample IDs matches your phenotype data sample IDs, otherwise your data will be scrambled + + #load(file = paste(path_to_GrimAgeV1_directory,"CalcGrimAgeV1.RData", sep = "")) + #print("Loaded GrimAgeV1 data.") + + #If needed: Fill in missing CpGs needed for calculation of PCs; use mean values from GSE40279 (Hannum 2013; blood)- note that for other tissues you might prefer to use a different one + datMeth <- as.data.frame(datMeth) + if(length(c(CpGs_GrimAge1[!(CpGs_GrimAge1 %in% colnames(datMeth))],CpGs_GrimAge1[apply(datMeth[,colnames(datMeth) %in% CpGs_GrimAge1], 2, function(x)all(is.na(x)))])) == 0){ + message("GrimAgeV1 - No CpGs were NA for all samples") + } else{ + missingCpGs_GrimAge1 <- c(CpGs_GrimAge1[!(CpGs_GrimAge1 %in% colnames(datMeth))]) + datMeth[,missingCpGs_GrimAge1] <- NA + datMeth = datMeth[,CpGs_GrimAge1] + missingCpGs_GrimAge1 <- CpGs_GrimAge1[apply(datMeth[,CpGs_GrimAge1], 2, function(x)all(is.na(x)))] + for(i in 1:length(missingCpGs_GrimAge1)){ + if (!is.na(imputeMissingCpGs_GrimAge1[missingCpGs_GrimAge1[i]])){ + datMeth[,missingCpGs_GrimAge1[i]] <- imputeMissingCpGs_GrimAge1[missingCpGs_GrimAge1[i]] + #print(imputeMissingCpGs_GrimAge1[missingCpGs_GrimAge1[i]]) + } + else{ + datMeth[,missingCpGs_GrimAge1[i]] <- 0 + + } + } + message(paste0("GrimAgeV1 needed to fill in ", length(missingCpGs_GrimAge1), " CpGs...")) + } + + #Prepare methylation data for calculation of PC Clocks (subset to 78,464 CpGs and perform imputation if needed) + #datMeth <- datMeth[,CpGs] + #meanimpute <- function(x) ifelse(is.na(x),mean(x,na.rm=T),x) + #datMeth <- apply(datMeth,2,meanimpute) + #Note: you may substitute another imputation method of your choice (e.g. KNN), but we have not found the method makes a significant difference. + #message("Mean imputation successfully completed for any missing CpG values") + + #Initialize a data frame for PC clocks + DNAmAge <- datPheno + + # Calculate GrimAge Clocks + temp <- as.matrix(cbind(datMeth, Age = as.numeric(datPheno$Age, Female=datPheno$Female))) + DNAmAge$DNAmPACKYRS <- as.numeric(temp[,names(CalcGrimAgeV1$PACKYRS.model)] %*% CalcGrimAgeV1$PACKYRS.model + CalcGrimAgeV1$PACKYRS.intercept) + DNAmAge$DNAmADM <- as.numeric(temp[,names(CalcGrimAgeV1$ADM.model)] %*% CalcGrimAgeV1$ADM.model + CalcGrimAgeV1$ADM.intercept) + DNAmAge$DNAmB2M <- as.numeric(temp[,names(CalcGrimAgeV1$B2M.model)] %*% CalcGrimAgeV1$B2M.model + CalcGrimAgeV1$B2M.intercept) + DNAmAge$DNAmCystatinC <- as.numeric(temp[,names(CalcGrimAgeV1$CystatinC.model)] %*% CalcGrimAgeV1$CystatinC.model + CalcGrimAgeV1$CystatinC.intercept) + DNAmAge$DNAmGDF15 <- as.numeric(temp[,names(CalcGrimAgeV1$GDF15.model)] %*% CalcGrimAgeV1$GDF15.model + CalcGrimAgeV1$GDF15.intercept) + DNAmAge$DNAmLeptin <- as.numeric(temp[,names(CalcGrimAgeV1$Leptin.model)] %*% CalcGrimAgeV1$Leptin.model + CalcGrimAgeV1$Leptin.intercept) + DNAmAge$DNAmPAI1 <- as.numeric(temp[,names(CalcGrimAgeV1$PAI1.model)] %*% CalcGrimAgeV1$PAI1.model + CalcGrimAgeV1$PAI1.intercept) + DNAmAge$DNAmTIMP1 <- as.numeric(temp[,names(CalcGrimAgeV1$TIMP1.model)] %*% CalcGrimAgeV1$TIMP1.model + CalcGrimAgeV1$TIMP1.intercept) + #print("Components Calculated.Calculating GrimAGE...") + DNAmAge$Age<-DNAmAge$Age + DNAmAge$Female<-DNAmAge$Female + DNAmAge$GrimAgeV1 <- as.numeric(as.matrix(DNAmAge[,CalcGrimAgeV1$components]) %*% CalcGrimAgeV1$GrimAge.model ) #+ CalcGrimAgeV1$GrimAge.intercept) + y<-DNAmAge$GrimAgeV1 + DNAmAge$GrimAgeV1 <- (((y- CalcGrimAgeV1$GrimAge.transform[3])/CalcGrimAgeV1$GrimAge.transform[4])*CalcGrimAgeV1$GrimAge.transform[2]) + CalcGrimAgeV1$GrimAge.transform[1] + + return(DNAmAge) + +} diff --git a/R/calcGrimAgeV2.R b/R/calcGrimAgeV2.R new file mode 100644 index 0000000..98fcb5b --- /dev/null +++ b/R/calcGrimAgeV2.R @@ -0,0 +1,101 @@ +#' calcGrimAge2V2 +#' +#' @description A function to calculate GrimAgeV2 +#' +#' @param DNAm a matrix of methylation beta values. Needs to be rows = samples and columns = CpGs, with rownames and colnames. +#' @param pheno Optional: The sample phenotype data (also with samples as rows) that the clock will be appended to. +#' @return If you added the optional pheno input (preferred) the function appends a column with the clock calculation and returns the dataframe. Otherwise, it will return a vector of calculated clock values in order of the +#' @export +#' +#' @examples calcPhenoAge(exampleBetas, examplePheno) +#' +#' + +calcGrimAgeV2 <- function(datMeth, datPheno){ + if(!("Age" %in% variable.names(datPheno))){ + stop("Error: datPheno must have a column named Age") + } + if(!("Female" %in% variable.names(datPheno))){ + stop("Error: datPheno must have a column named Female") + } + if(sum(startsWith(colnames(datMeth),"cg")) == 0){ + warning("Warning: It looks like you may need to format datMeth using t(datMeth) to get samples as rows!") + } + + #In datPheno, rows are samples and columns are phenotypic variables. + #One of the phenotypic variables must be "Age", and another one "Female" (coded as Female = 1, Male = 0; should be a numeric variable as this will be included in PCGrimAge calculation) + #Also ensure that the order of datMeth sample IDs matches your phenotype data sample IDs, otherwise your data will be scrambled + + #load(file = paste(path_to_GrimAgeV2_directory,"CalcGrimAgeV2.RData", sep = "")) + #print("Loaded GrimAgeV2 data.") + + #If needed: Fill in missing CpGs needed for calculation of PCs; use mean values from GSE40279 (Hannum 2013; blood)- note that for other tissues you might prefer to use a different one + # datMeth <- as.data.frame(datMeth) + # if(length(c(CpGs[!(CpGs %in% colnames(datMeth))],CpGs[apply(datMeth[,colnames(datMeth) %in% CpGs], 2, function(x)all(is.na(x)))])) == 0){ + # message("No CpGs were NA for all samples") + # } else{ + # missingCpGs <- c(CpGs[!(CpGs %in% colnames(datMeth))]) + # datMeth[,missingCpGs] <- NA + # datMeth = datMeth[,CpGs] + # missingCpGs <- CpGs[apply(datMeth[,CpGs], 2, function(x)all(is.na(x)))] + # for(i in 1:length(missingCpGs)){ + # datMeth[,missingCpGs[i]] <- imputeMissingCpGs[missingCpGs[i]] + # } + # message("Any missing CpGs successfully filled in (see function for more details)") + # } + + datMeth <- as.data.frame(datMeth) + if(length(c(CpGs_GrimAge2[!(CpGs_GrimAge2 %in% colnames(datMeth))],CpGs_GrimAge2[apply(datMeth[,colnames(datMeth) %in% CpGs_GrimAge2], 2, function(x)all(is.na(x)))])) == 0){ + message("GrimAgeV2 - No CpGs were NA for all samples") + } else{ + missingCpGs_GrimAge2 <- c(CpGs_GrimAge2[!(CpGs_GrimAge2 %in% colnames(datMeth))]) + datMeth[,missingCpGs_GrimAge2] <- NA + datMeth = datMeth[,CpGs_GrimAge2] + missingCpGs_GrimAge2 <- CpGs_GrimAge2[apply(datMeth[,CpGs_GrimAge2], 2, function(x)all(is.na(x)))] + for(i in 1:length(missingCpGs_GrimAge2)){ + if (!is.na(imputeMissingCpGs_GrimAge2[missingCpGs_GrimAge2[i]])){ + datMeth[,missingCpGs_GrimAge2[i]] <- imputeMissingCpGs_GrimAge2[missingCpGs_GrimAge2[i]] + #print(imputeMissingCpGs_GrimAge2[missingCpGs_GrimAge2[i]]) + } + else{ + datMeth[,missingCpGs_GrimAge2[i]] <- 0 + } + } + message(paste0("GrimAgeV2 needed to fill in ", length(missingCpGs_GrimAge2), " CpGs...")) + } + + #Prepare methylation data for calculation of PC Clocks (subset to 78,464 CpGs and perform imputation if needed) + #datMeth <- datMeth[,CpGs] + #meanimpute <- function(x) ifelse(is.na(x),mean(x,na.rm=T),x) + #datMeth <- apply(datMeth,2,meanimpute) + #Note: you may substitute another imputation method of your choice (e.g. KNN), but we have not found the method makes a significant difference. + #message("Mean imputation successfully completed for any missing CpG values") + + #Initialize a data frame for PC clocks + DNAmAge <- datPheno + + # Calculate GrimAge Clocks + temp <- as.matrix(cbind(datMeth, Age = as.numeric(datPheno$Age, Female=datPheno$Female))) + DNAmAge$DNAmPACKYRS <- as.numeric(temp[,names(CalcGrimAge2$PACKYRS.model)] %*% CalcGrimAge2$PACKYRS.model + CalcGrimAge2$PACKYRS.intercept) + DNAmAge$DNAmADM <- as.numeric(temp[,names(CalcGrimAge2$ADM.model)] %*% CalcGrimAge2$ADM.model + CalcGrimAge2$ADM.intercept) + DNAmAge$DNAmB2M <- as.numeric(temp[,names(CalcGrimAge2$B2M.model)] %*% CalcGrimAge2$B2M.model + CalcGrimAge2$B2M.intercept) + DNAmAge$DNAmCystatinC <- as.numeric(temp[,names(CalcGrimAge2$CystatinC.model)] %*% CalcGrimAge2$CystatinC.model + CalcGrimAge2$CystatinC.intercept) + DNAmAge$DNAmGDF15 <- as.numeric(temp[,names(CalcGrimAge2$GDF15.model)] %*% CalcGrimAge2$GDF15.model + CalcGrimAge2$GDF15.intercept) + DNAmAge$DNAmLeptin <- as.numeric(temp[,names(CalcGrimAge2$Leptin.model)] %*% CalcGrimAge2$Leptin.model + CalcGrimAge2$Leptin.intercept) + DNAmAge$DNAmPAI1 <- as.numeric(temp[,names(CalcGrimAge2$PAI1.model)] %*% CalcGrimAge2$PAI1.model + CalcGrimAge2$PAI1.intercept) + DNAmAge$DNAmTIMP1 <- as.numeric(temp[,names(CalcGrimAge2$TIMP1.model)] %*% CalcGrimAge2$TIMP1.model + CalcGrimAge2$TIMP1.intercept) + #New Proteins + DNAmAge$DNAmlogA1C <- as.numeric(temp[,names(CalcGrimAge2$logA1C.model)] %*% CalcGrimAge2$logA1C.model + CalcGrimAge2$logA1C.intercept) + DNAmAge$DNAmlogCRP <- as.numeric(temp[,names(CalcGrimAge2$logCRP.model)] %*% CalcGrimAge2$logCRP.model + CalcGrimAge2$logCRP.intercept) + + # DNAmAge$Age<-DNAmAge$cAGE + # DNAmAge$Female<-DNAmAge$cFEMALE + + DNAmAge$GrimAgeV2 <- as.numeric(as.matrix(DNAmAge[,CalcGrimAge2$components]) %*% CalcGrimAge2$GrimAge.model ) #+ CalcGrimAge2$GrimAge.intercept) + y<-DNAmAge$GrimAgeV2 + #print(y) + DNAmAge$GrimAgeV2 <- (((y- CalcGrimAge2$GrimAge.transform[3])/CalcGrimAge2$GrimAge.transform[4])*CalcGrimAge2$GrimAge.transform[2]) + CalcGrimAge2$GrimAge.transform[1] + + return(DNAmAge) + +} diff --git a/R/calcHRSInChPhenoAge.R b/R/calcHRSInChPhenoAge.R index f2e4b72..2f8322d 100644 --- a/R/calcHRSInChPhenoAge.R +++ b/R/calcHRSInChPhenoAge.R @@ -10,8 +10,8 @@ #' @return If you added the optional pheno input (preferred) the function appends a column with the clock calculation and returns the dataframe. Otherwise, it will return a vector of calculated clock values in order of the #' @export #' -#' @examples calcHRSInChPhenoAge(exampleBetas, examplePheno, imputation = F) -calcHRSInChPhenoAge <- function(DNAm, pheno = NULL, CpGImputation = NULL, imputation = F){ +#' @examples calcHRSInChPhenoAge(exampleBetas, examplePheno, imputation = T) +calcHRSInChPhenoAge <- function(DNAm, pheno = NULL, CpGImputation = NULL, imputation = T){ ####################### ### Read in the Data### diff --git a/R/calcHannum.R b/R/calcHannum.R index 83d3b27..2fbd23a 100644 --- a/R/calcHannum.R +++ b/R/calcHannum.R @@ -10,8 +10,8 @@ #' @return If you added the optional pheno input (preferred) the function appends a column with the clock calculation and returns the dataframe. Otherwise, it will return a vector of calculated clock values in order of the #' @export #' -#' @examples calcHannum(exampleBetas, examplePheno, imputation = F) -calcHannum <- function(DNAm, pheno = NULL, CpGImputation = NULL, imputation = F){ +#' @examples calcHannum(exampleBetas, examplePheno, imputation = T) +calcHannum <- function(DNAm, pheno = NULL, CpGImputation = NULL, imputation = T){ ####################### ### Read in the Data### diff --git a/R/calcHorvath1.R b/R/calcHorvath1.R index 754013d..ec271b2 100644 --- a/R/calcHorvath1.R +++ b/R/calcHorvath1.R @@ -10,8 +10,8 @@ #' @return If you added the optional pheno input (preferred) the function appends a column with the clock calculation and returns the dataframe. Otherwise, it will return a vector of calculated clock values in order of the #' @export #' -#' @examples calcHorvath1(exampleBetas, examplePheno, imputation = F) -calcHorvath1 <- function(DNAm, pheno = NULL, CpGImputation = NULL, imputation = F){ +#' @examples calcHorvath1(exampleBetas, examplePheno, imputation = T) +calcHorvath1 <- function(DNAm, pheno = NULL, CpGImputation = NULL, imputation = T){ ####################### ### Read in the Data### diff --git a/R/calcHorvath2.R b/R/calcHorvath2.R index eeecce6..d00c5d7 100644 --- a/R/calcHorvath2.R +++ b/R/calcHorvath2.R @@ -10,8 +10,8 @@ #' @return If you added the optional pheno input (preferred) the function appends a column with the clock calculation and returns the dataframe. Otherwise, it will return a vector of calculated clock values in order of the #' @export #' -#' @examples calcHorvath2(exampleBetas, examplePheno, imputation = F) -calcHorvath2 <- function(DNAm, pheno = NULL, CpGImputation = NULL, imputation = F){ +#' @examples calcHorvath2(exampleBetas, examplePheno, imputation = T) +calcHorvath2 <- function(DNAm, pheno = NULL, CpGImputation = NULL, imputation = T){ ####################### ### Read in the Data### diff --git a/R/calcHypoClock.R b/R/calcHypoClock.R index 99220af..165ae49 100644 --- a/R/calcHypoClock.R +++ b/R/calcHypoClock.R @@ -11,8 +11,8 @@ #' @export #' @source #' -#' @examples calcHypoClock(exampleBetas, examplePheno, imputation = F) -calcHypoClock <- function(DNAm, pheno = NULL, CpGImputation = NULL, imputation = F){ +#' @examples calcHypoClock(exampleBetas, examplePheno, imputation = T) +calcHypoClock <- function(DNAm, pheno = NULL, CpGImputation = NULL, imputation = T){ ####################### ### Read in the Data### diff --git a/R/calcKnight.R b/R/calcKnight.R index 64971f7..198ebef 100644 --- a/R/calcKnight.R +++ b/R/calcKnight.R @@ -10,8 +10,8 @@ #' @return If you added the optional pheno input (preferred) the function appends a column with the clock calculation and returns the dataframe. Otherwise, it will return a vector of calculated clock values in order of the #' @export #' -#' @examples calcKnight(exampleBetas, examplePheno, imputation = F) -calcKnight <- function(DNAm, pheno = NULL, CpGImputation = NULL, imputation = F){ +#' @examples calcKnight(exampleBetas, examplePheno, imputation = T) +calcKnight <- function(DNAm, pheno = NULL, CpGImputation = NULL, imputation = T){ ####################### ### Read in the Data### diff --git a/R/calcLeeControl.R b/R/calcLeeControl.R index 184b229..ebd3d49 100644 --- a/R/calcLeeControl.R +++ b/R/calcLeeControl.R @@ -10,8 +10,8 @@ #' @return If you added the optional pheno input (preferred) the function appends a column with the clock calculation and returns the dataframe. Otherwise, it will return a vector of calculated clock values in order of the #' @export #' -#' @examples calcLeeControl(exampleBetas, examplePheno, imputation = F) -calcLeeControl <- function(DNAm, pheno = NULL, CpGImputation = NULL, imputation = F){ +#' @examples calcLeeControl(exampleBetas, examplePheno, imputation = T) +calcLeeControl <- function(DNAm, pheno = NULL, CpGImputation = NULL, imputation = T){ ####################### ### Read in the Data### diff --git a/R/calcLeeRefinedRobust.R b/R/calcLeeRefinedRobust.R index fc8f797..148e88a 100644 --- a/R/calcLeeRefinedRobust.R +++ b/R/calcLeeRefinedRobust.R @@ -10,8 +10,8 @@ #' @return If you added the optional pheno input (preferred) the function appends a column with the clock calculation and returns the dataframe. Otherwise, it will return a vector of calculated clock values in order of the #' @export #' -#' @examples calcLeeRefinedRobust(exampleBetas, examplePheno, imputation = F) -calcLeeRefinedRobust <- function(DNAm, pheno = NULL, CpGImputation = NULL, imputation = F){ +#' @examples calcLeeRefinedRobust(exampleBetas, examplePheno, imputation = T) +calcLeeRefinedRobust <- function(DNAm, pheno = NULL, CpGImputation = NULL, imputation = T){ ####################### ### Read in the Data### diff --git a/R/calcLeeRobust.R b/R/calcLeeRobust.R index 30a66d9..c34e211 100644 --- a/R/calcLeeRobust.R +++ b/R/calcLeeRobust.R @@ -10,8 +10,8 @@ #' @return If you added the optional pheno input (preferred) the function appends a column with the clock calculation and returns the dataframe. Otherwise, it will return a vector of calculated clock values in order of the #' @export #' -#' @examples calcLeeRobust(exampleBetas, examplePheno, imputation = F) -calcLeeRobust <- function(DNAm, pheno = NULL, CpGImputation = NULL, imputation = F){ +#' @examples calcLeeRobust(exampleBetas, examplePheno, imputation = T) +calcLeeRobust <- function(DNAm, pheno = NULL, CpGImputation = NULL, imputation = T){ ####################### ### Read in the Data### diff --git a/R/calcLin.R b/R/calcLin.R index f74287a..29a9045 100644 --- a/R/calcLin.R +++ b/R/calcLin.R @@ -10,8 +10,8 @@ #' @return If you added the optional pheno input (preferred) the function appends a column with the clock calculation and returns the dataframe. Otherwise, it will return a vector of calculated clock values in order of the #' @export #' -#' @examples calcHRSInChPhenoAge(exampleBetas, examplePheno, imputation = F) -calcLin <- function(DNAm, pheno = NULL, CpGImputation = NULL, imputation = F){ +#' @examples calcHRSInChPhenoAge(exampleBetas, examplePheno, imputation = T) +calcLin <- function(DNAm, pheno = NULL, CpGImputation = NULL, imputation = T){ ####################### ### Read in the Data### diff --git a/R/calcMayne.R b/R/calcMayne.R index 6c5d396..9275a16 100644 --- a/R/calcMayne.R +++ b/R/calcMayne.R @@ -10,9 +10,9 @@ #' @return If you added the optional pheno input (preferred) the function appends a column with the clock calculation and returns the dataframe. Otherwise, it will return a vector of calculated clock values in order of the #' @export #' -#' @examples calcMayne(exampleBetas, examplePheno, imputation = F) +#' @examples calcMayne(exampleBetas, examplePheno, imputation = T) #' @examples calcMayne(exampleBetas, examplePheno, imputation = T, CpGImputation = Mayne_impute) #For the Mayne imputation gold standard -calcMayne <- function(DNAm, pheno = NULL, CpGImputation = NULL, imputation = F){ +calcMayne <- function(DNAm, pheno = NULL, CpGImputation = NULL, imputation = T){ ####################### ### Read in the Data### diff --git a/R/calcMiAge.R b/R/calcMiAge.R index 9781cc0..48072fc 100644 --- a/R/calcMiAge.R +++ b/R/calcMiAge.R @@ -10,8 +10,8 @@ #' @return If you added the optional pheno input (preferred) the function appends a column with the clock calculation and returns the dataframe. Otherwise, it will return a vector of calculated clock values in order of the #' @export #' -#' @examples calcMiAge(exampleBetas, examplePheno, imputation = F) -calcMiAge <- function(DNAm, pheno = NULL, CpGImputation = NULL, imputation = F){ +#' @examples calcMiAge(exampleBetas, examplePheno, imputation = T) +calcMiAge <- function(DNAm, pheno = NULL, CpGImputation = NULL, imputation = T){ ####################### ### Read in the Data### diff --git a/R/calcPCClocks.R b/R/calcPCClocks.R new file mode 100644 index 0000000..1da8073 --- /dev/null +++ b/R/calcPCClocks.R @@ -0,0 +1,137 @@ +#' calcPCClocks +#' +#' @description A function to calculate all PC Clocks +#' +#' @param DNAm a matrix of methylation beta values. Needs to be rows = samples and columns = CpGs, with rownames and colnames. +#' @param pheno Optional: The sample phenotype data (also with samples as rows) that the clock will be appended to. +#' @return If you added the optional pheno input (preferred) the function appends a column with the clock calculation and returns the dataframe. Otherwise, it will return a vector of calculated clock values in order of the +#' @export +#' +#' @examples calcPhenoAge(exampleBetas, examplePheno) +#' +#' + +calcPCClocks <- function(datMeth, datPheno){ + + setwd(dirname(rstudioapi::getActiveDocumentContext()$path)) + + + #add check that path_to_PCClocks ends with a / + + #path_to_PCClocks should end with a "/" + #datMeth is a matrix of methylation Beta values, where row names are samples, and + # column names are CpGs + #datPheno has rows as samples and columns as phenotype variables. This can also + # include the original clocks if you used the Horvath online calculator as well. + # It MUST include a column named "Age" and a column named "Female" + + if(!("Age" %in% variable.names(datPheno))){ + stop("Error: datPheno must have a column named Age") + } + if(!("Female" %in% variable.names(datPheno))){ + stop("Error: datPheno must have a column named Female") + } + if(sum(startsWith(colnames(datMeth),"cg")) == 0){ + warning("Warning: It looks like you may need to format datMeth using t(datMeth) to get samples as rows!") + } + + + #Note: this code assumes all your files are in one working directory. Alter the code as needed based on file locations. + #Load packages + pkgTest <- function(x) + { + if (!require(x,character.only = TRUE)) + { + install.packages(x,dep=TRUE) + if(!require(x,character.only = TRUE)) stop("Package not found") + } + } + pkgTest("dplyr") + library(dplyr) + pkgTest("tibble") + library(tibble) + pkgTest("tidyr") + library(tidyr) + pkgTest("googledrive") + library(googledrive) + + googledrive::drive_auth() + + + #In datPheno, rows are samples and columns are phenotypic variables. + #One of the phenotypic variables must be "Age", and another one "Female" (coded as Female = 1, Male = 0; should be a numeric variable as this will be included in PCGrimAge calculation) + #Also ensure that the order of datMeth sample IDs matches your phenotype data sample IDs, otherwise your data will be scrambled + + home_dir<-Sys.getenv("HOME") + + if (file.exists(paste0(home_dir,"/CalcAllPCClocks.RData"))) { + cat("PCClocks File Exists in Home Directory. Loading Data...\n") + load(paste0(home_dir,"/CalcAllPCClocks.RData")) + } else { + cat("PCClocks Data does not exist in package directory. Downloading data...\n") + public_file <- drive_get(as_id("1xhFUMBSrjRta3tgL0OTBLVgNlLnJJNRZ")) + drive_download(public_file, path = paste0(home_dir,"/CalcAllPCClocks.RData"), overwrite = TRUE) + load(paste0(home_dir,"/CalcAllPCClocks.RData")) + } + + #load(file = paste(path_to_PCClocks_directory,"CalcAllPCClocks.RData", sep = "")) + + message("PCClocks Data successfully loaded") + + #If needed: Fill in missing CpGs needed for calculation of PCs; use mean values from GSE40279 (Hannum 2013; blood)- note that for other tissues you might prefer to use a different one + datMeth <- as.data.frame(datMeth) + if(length(c(CpGs[!(CpGs %in% colnames(datMeth))],CpGs[apply(datMeth[,colnames(datMeth) %in% CpGs], 2, function(x)all(is.na(x)))])) == 0){ + message("PCClocks - No CpGs were NA for all samples") + } else{ + missingCpGs <- c(CpGs[!(CpGs %in% colnames(datMeth))]) + datMeth[,missingCpGs] <- NA + datMeth = datMeth[,CpGs] + missingCpGs <- CpGs[apply(datMeth[,CpGs], 2, function(x)all(is.na(x)))] + for(i in 1:length(missingCpGs)){ + datMeth[,missingCpGs[i]] <- imputeMissingCpGs[missingCpGs[i]] + } + message("PCClocks - Any missing CpGs successfully filled in (see function for more details)") + } + + #Prepare methylation data for calculation of PC Clocks (subset to 78,464 CpGs and perform imputation if needed) + datMeth <- datMeth[,CpGs] + meanimpute <- function(x) ifelse(is.na(x),mean(x,na.rm=T),x) + datMeth <- apply(datMeth,2,meanimpute) + #Note: you may substitute another imputation method of your choice (e.g. KNN), but we have not found the method makes a significant difference. + message("Mean imputation successfully completed for any missing CpG values") + + #Initialize a data frame for PC clocks + DNAmAge <- datPheno + + #var = readline(prompt = "To check whether datMeth and datPheno match up, type the column name in datPheno with sample names (or type skip):") + #if(var != "skip"){ + # if(sum(DNAmAge[,var] == rownames(datMeth)) != dim(DNAmAge[,var])[1]){ + # warning("Warning: It would appear that datPheno and datMeth do not have matching sample order! Check your inputs!") + # } else message("datPheno and datMeth sample order verified to match!") + #} + + message("Calculating PC Clocks now") + + #Calculate PC Clocks + DNAmAge$PCHorvath1 <- as.numeric(anti.trafo(sweep(as.matrix(datMeth),2,CalcPCHorvath1$center) %*% CalcPCHorvath1$rotation %*% CalcPCHorvath1$model + CalcPCHorvath1$intercept)) + DNAmAge$PCHorvath2 <- as.numeric(anti.trafo(sweep(as.matrix(datMeth),2,CalcPCHorvath2$center) %*% CalcPCHorvath2$rotation %*% CalcPCHorvath2$model + CalcPCHorvath2$intercept)) + DNAmAge$PCHannum <- as.numeric(sweep(as.matrix(datMeth),2,CalcPCHannum$center) %*% CalcPCHannum$rotation %*% CalcPCHannum$model + CalcPCHannum$intercept) + DNAmAge$PCPhenoAge <- as.numeric(sweep(as.matrix(datMeth),2,CalcPCPhenoAge$center) %*% CalcPCPhenoAge$rotation %*% CalcPCPhenoAge$model + CalcPCPhenoAge$intercept) + DNAmAge$PCDNAmTL <- as.numeric(sweep(as.matrix(datMeth),2,CalcPCDNAmTL$center) %*% CalcPCDNAmTL$rotation %*% CalcPCDNAmTL$model + CalcPCDNAmTL$intercept) + temp <- cbind(sweep(as.matrix(datMeth),2,CalcPCGrimAge$center) %*% CalcPCGrimAge$rotation,Female = DNAmAge$Female,Age = DNAmAge$Age) + DNAmAge$PCPACKYRS <- as.numeric(temp[,names(CalcPCGrimAge$PCPACKYRS.model)] %*% CalcPCGrimAge$PCPACKYRS.model + CalcPCGrimAge$PCPACKYRS.intercept) + DNAmAge$PCADM <- as.numeric(temp[,names(CalcPCGrimAge$PCADM.model)] %*% CalcPCGrimAge$PCADM.model + CalcPCGrimAge$PCADM.intercept) + DNAmAge$PCB2M <- as.numeric(temp[,names(CalcPCGrimAge$PCB2M.model)] %*% CalcPCGrimAge$PCB2M.model + CalcPCGrimAge$PCB2M.intercept) + DNAmAge$PCCystatinC <- as.numeric(temp[,names(CalcPCGrimAge$PCCystatinC.model)] %*% CalcPCGrimAge$PCCystatinC.model + CalcPCGrimAge$PCCystatinC.intercept) + DNAmAge$PCGDF15 <- as.numeric(temp[,names(CalcPCGrimAge$PCGDF15.model)] %*% CalcPCGrimAge$PCGDF15.model + CalcPCGrimAge$PCGDF15.intercept) + DNAmAge$PCLeptin <- as.numeric(temp[,names(CalcPCGrimAge$PCLeptin.model)] %*% CalcPCGrimAge$PCLeptin.model + CalcPCGrimAge$PCLeptin.intercept) + DNAmAge$PCPAI1 <- as.numeric(temp[,names(CalcPCGrimAge$PCPAI1.model)] %*% CalcPCGrimAge$PCPAI1.model + CalcPCGrimAge$PCPAI1.intercept) + DNAmAge$PCTIMP1 <- as.numeric(temp[,names(CalcPCGrimAge$PCTIMP1.model)] %*% CalcPCGrimAge$PCTIMP1.model + CalcPCGrimAge$PCTIMP1.intercept) + DNAmAge$PCGrimAge <- as.numeric(as.matrix(DNAmAge[,CalcPCGrimAge$components]) %*% CalcPCGrimAge$PCGrimAge.model + CalcPCGrimAge$PCGrimAge.intercept) + rm(CalcPCHorvath1,CalcPCHorvath2,CalcPCHannum,CalcPCPhenoAge,CalcPCDNAmTL,CalcPCGrimAge,temp,imputeMissingCpGs) + + message("PC Clocks successfully calculated!") + + return(DNAmAge) +} + diff --git a/R/calcPEDBE.R b/R/calcPEDBE.R index 44316e3..105eedd 100644 --- a/R/calcPEDBE.R +++ b/R/calcPEDBE.R @@ -10,8 +10,8 @@ #' @return If you added the optional pheno input (preferred) the function appends a column with the clock calculation and returns the dataframe. Otherwise, it will return a vector of calculated clock values in order of the #' @export #' -#' @examples calcPEDBE(exampleBetas, examplePheno, imputation = F) -calcPEDBE <- function(DNAm, pheno = NULL, CpGImputation = NULL, imputation = F){ +#' @examples calcPEDBE(exampleBetas, examplePheno, imputation = T) +calcPEDBE <- function(DNAm, pheno = NULL, CpGImputation = NULL, imputation = T){ ####################### ### Read in the Data### diff --git a/R/calcPhenoAge.R b/R/calcPhenoAge.R index 221074a..8ceb47c 100644 --- a/R/calcPhenoAge.R +++ b/R/calcPhenoAge.R @@ -10,8 +10,8 @@ #' @return If you added the optional pheno input (preferred) the function appends a column with the clock calculation and returns the dataframe. Otherwise, it will return a vector of calculated clock values in order of the #' @export #' -#' @examples calcPhenoAge(exampleBetas, examplePheno, imputation = F) -calcPhenoAge <- function(DNAm, pheno = NULL, CpGImputation = NULL, imputation = F){ +#' @examples calcPhenoAge(exampleBetas, examplePheno, imputation = T) +calcPhenoAge <- function(DNAm, pheno = NULL, CpGImputation = NULL, imputation = T){ ####################### ### Read in the Data### diff --git a/R/calcSmokingMcCartney.R b/R/calcSmokingMcCartney.R index 276b2f6..a670bc9 100644 --- a/R/calcSmokingMcCartney.R +++ b/R/calcSmokingMcCartney.R @@ -10,8 +10,8 @@ #' @return If you added the optional pheno input (preferred) the function appends a column with the clock calculation and returns the dataframe. Otherwise, it will return a vector of calculated clock values in order of the #' @export #' -#' @examples calcSmokingMcCartney(exampleBetas, examplePheno, imputation = F) -calcSmokingMcCartney <- function(DNAm, pheno = NULL, CpGImputation = NULL, imputation = F){ +#' @examples calcSmokingMcCartney(exampleBetas, examplePheno, imputation = T) +calcSmokingMcCartney <- function(DNAm, pheno = NULL, CpGImputation = NULL, imputation = T){ ####################### ### Read in the Data### diff --git a/R/calcUserClocks.R b/R/calcUserClocks.R index c3c5b4d..e4880af 100644 --- a/R/calcUserClocks.R +++ b/R/calcUserClocks.R @@ -12,8 +12,8 @@ #' @export #' #' @examples userClocks <- c("calcSmokingMcCartney","calcPhenoAge","calcEpiTOC2") -#' @examples calcUserClocks(userClocks, exampleBetas, examplePheno, imputation = F) -calcUserClocks <- function(clockList, DNAm, pheno , CpGImputation = NULL, imputation = F){ +#' @examples calcUserClocks(userClocks, exampleBetas, examplePheno, imputation = T) +calcUserClocks <- function(clockList, DNAm, pheno , CpGImputation = NULL, imputation = T){ for(i in 1:length(clockList)){ diff --git a/R/calcVidalBralo.R b/R/calcVidalBralo.R index 4804b92..3b79f1d 100644 --- a/R/calcVidalBralo.R +++ b/R/calcVidalBralo.R @@ -10,8 +10,8 @@ #' @return If you added the optional pheno input (preferred) the function appends a column with the clock calculation and returns the dataframe. Otherwise, it will return a vector of calculated clock values in order of the #' @export #' -#' @examples calcVidalBralo(exampleBetas, examplePheno, imputation = F) -calcVidalBralo <- function(DNAm, pheno = NULL, CpGImputation = NULL, imputation = F){ +#' @examples calcVidalBralo(exampleBetas, examplePheno, imputation = T) +calcVidalBralo <- function(DNAm, pheno = NULL, CpGImputation = NULL, imputation = T){ ####################### ### Read in the Data### diff --git a/R/calcWeidner.R b/R/calcWeidner.R index fcec809..6e72df9 100644 --- a/R/calcWeidner.R +++ b/R/calcWeidner.R @@ -10,8 +10,8 @@ #' @return If you added the optional pheno input (preferred) the function appends a column with the clock calculation and returns the dataframe. Otherwise, it will return a vector of calculated clock values in order of the #' @export #' -#' @examples calcWeidner(exampleBetas, examplePheno, imputation = F) -calcWeidner <- function(DNAm, pheno = NULL, CpGImputation = NULL, imputation = F){ +#' @examples calcWeidner(exampleBetas, examplePheno, imputation = T) +calcWeidner <- function(DNAm, pheno = NULL, CpGImputation = NULL, imputation = T){ ####################### ### Read in the Data### diff --git a/R/calcZhang.R b/R/calcZhang.R index c8e097c..94b2ef2 100644 --- a/R/calcZhang.R +++ b/R/calcZhang.R @@ -10,8 +10,8 @@ #' @return If you added the optional pheno input (preferred) the function appends a column with the clock calculation and returns the dataframe. Otherwise, it will return a vector of calculated clock values in order of the #' @export #' -#' @examples calcZhang(exampleBetas, examplePheno, imputation = F) -calcZhang <- function(DNAm, pheno = NULL, CpGImputation = NULL, imputation = F){ +#' @examples calcZhang(exampleBetas, examplePheno, imputation = T) +calcZhang <- function(DNAm, pheno = NULL, CpGImputation = NULL, imputation = T){ ####################### ### Read in the Data### @@ -39,7 +39,7 @@ calcZhang <- function(DNAm, pheno = NULL, CpGImputation = NULL, imputation = F){ betas <- DNAm[,na.omit(match(Zhang_10_CpG$Marker,colnames(DNAm)))] - tt <- rowSums(sweep(betas, MARGIN = 2, Zhang_10_CpG$coef[present],`*`), na.rm = T) + tt <- rowSums(sweep(as.matrix(betas), MARGIN = 2, Zhang_10_CpG$coef[present],`*`), na.rm = T) if(is.null(pheno)){ tt diff --git a/R/calcZhang2019.R b/R/calcZhang2019.R index 86ff04b..5f09221 100644 --- a/R/calcZhang2019.R +++ b/R/calcZhang2019.R @@ -10,8 +10,8 @@ #' @return If you added the optional pheno input (preferred) the function appends a column with the clock calculation and returns the dataframe. Otherwise, it will return a vector of calculated clock values in order of the #' @export #' -#' @examples calcZhang2019(exampleBetas, examplePheno, imputation = F) -calcZhang2019 <- function(DNAm, pheno = NULL, CpGImputation = NULL, imputation = F){ +#' @examples calcZhang2019(exampleBetas, examplePheno, imputation = T) +calcZhang2019 <- function(DNAm, pheno = NULL, CpGImputation = NULL, imputation = T){ ####################### ### Read in the Data### diff --git a/R/citeMyClocks.R b/R/citeMyClocks.R index 014d861..818147c 100644 --- a/R/citeMyClocks.R +++ b/R/citeMyClocks.R @@ -55,6 +55,18 @@ citeMyClocks <- function(clockList, prettyprint = TRUE){ if(any(c("calcLeeRobust","calcLeeControl","calcLeeRefinedRobust") %in% clockList)){ citations <- c(citations, "Lee, Y., Choufani, S., Weksberg, R., Wilson, S. L., Yuan, V., Burt, A., … Horvath, S. (2019). \n Placental epigenetic clocks: Estimating gestational age using placental DNA methylation levels. \n Aging, 11(12), 4238–4253. https://doi.org/10.18632/aging.102049")} + if("calcPCClocks" %in% clockList){ + citations <- c(citations, "Higgins-Chen, A. T., Thrush, K. L., Wang, Y., Minteer, C. J., Kuo, P. L., Wang, M., Niimi, P., Sturm, G., Lin, J., Moore, A. Z., Bandinelli, S., Vinkers, C. H., Vermetten, E., Rutten, B. P. F., Geuze, E., Okhuijsen-Pfeifer, C., van der Horst, M. Z., Schreiter, S., Gutwinski, S., Luykx, J. J., … Levine, M. E. (2022). \n A computational solution for bolstering reliability of epigenetic clocks: Implications for clinical trials and longitudinal tracking. \n Nature aging, 2(7), 644–661. https://doi.org/10.1038/s43587-022-00248-2")} + + if("calcGrimAgeV1" %in% clockList){ + citations <- c(citations, "Lu, A. T., Quach, A., Wilson, J. G., Reiner, A. P., Aviv, A., Raj, K., Hou, L., Baccarelli, A. A., Li, Y., Stewart, J. D., Whitsel, E. A., Assimes, T. L., Ferrucci, L., & Horvath, S. (2019). \n DNA methylation GrimAge strongly predicts lifespan and healthspan. \n Aging, 11(2), 303–327. https://doi.org/10.18632/aging.101684")} + + if("calcGrimAgeV2" %in% clockList){ + citations <- c(citations, "Lu, A. T., Binder, A. M., Zhang, J., Yan, Q., Reiner, A. P., Cox, S. R., Corley, J., Harris, S. E., Kuo, P. L., Moore, A. Z., Bandinelli, S., Stewart, J. D., Wang, C., Hamlat, E. J., Epel, E. S., Schwartz, J. D., Whitsel, E. A., Correa, A., Ferrucci, L., Marioni, R. E., … Horvath, S. \n (2022). DNA methylation GrimAge version 2. \n Aging, 14(23), 9484–9549. https://doi.org/10.18632/aging.204434")} + + if("calcSystemsAge" %in% clockList){ + citations <- c(citations, "Sehgal, R., Markov, Y., Qin, C., Meer, M., Hadley, C., Shadyab, A. H., Casanova, R., Manson, J. E., Bhatti, P., Crimmins, E. M., Hägg, S., Assimes, T. L., Whitsel, E. A., Higgins-Chen, A. T., & Levine, M. (2024). \n Systems Age: A single blood methylation test to quantify aging heterogeneity across 11 physiological systems. \n bioRxiv : the preprint server for biology, 2023.07.13.548904. https://doi.org/10.1101/2023.07.13.548904")} + if("calcPhenoAge" %in% clockList){ citations <- c(citations, "Levine, M. E., Lu, A. T., Quach, A., Chen, B. H., Assimes, T. L., Bandinelli, S., … Horvath, S. (2018). \n An epigenetic biomarker of aging for lifespan and healthspan. \n Aging, 10(4), 573–591. https://doi.org/10.18632/aging.101414")} diff --git a/R/getClockProbes.R b/R/getClockProbes.R index 4d3f441..e217da3 100644 --- a/R/getClockProbes.R +++ b/R/getClockProbes.R @@ -10,6 +10,7 @@ getClockProbes <- function(DNAm){ ClockDataList <- as.data.frame(data(package = "methylCIPHER")[3][[1]])$Item ClockDataList <- stringr::str_subset(ClockDataList, pattern = "CpG") + ClockDataList <- ClockDataList[grep("Calc",ClockDataList,invert=TRUE)] totalProbes <- vector(mode = "numeric", length = length(ClockDataList)) presentProbes <- vector(mode = "numeric", length = length(ClockDataList)) @@ -17,9 +18,11 @@ getClockProbes <- function(DNAm){ for(i in 1:length(ClockDataList)){ + x <- get(ClockDataList[i]) - if(ClockDataList[i] %in% c("Bocklandt_CpG","EpiToc_CpGs","hypoClock_CpGs","Garagnani_CpG","Weidner_CpGs")){ + if(ClockDataList[i] %in% c("Bocklandt_CpG","EpiToc_CpGs","hypoClock_CpGs", + "Garagnani_CpG","Weidner_CpGs","PCClocks_CpGs","SystemsAge_CpGs","eightfiftykCpGs")){ currentCpGList <- x @@ -39,7 +42,7 @@ getClockProbes <- function(DNAm){ CpGColumn <- grepl("CpG|Marker|ID|id", colnames(x)) - currentCpGList <- x[CpGColumn][,1] + currentCpGList <- as.matrix(x[CpGColumn][,1]) } @@ -47,6 +50,8 @@ getClockProbes <- function(DNAm){ presentProbes[i] <- sum(currentCpGList %in% colnames(DNAm)) percentPresent[i] <- paste(round((presentProbes[i]/totalProbes[i])*100,0),"%",sep = "") + + } ProbeTable <- data.frame(Clock = sapply(strsplit(ClockDataList,"_"), `[`, 1), @@ -56,4 +61,6 @@ getClockProbes <- function(DNAm){ ProbeTable + + } diff --git a/data/.DS_Store b/data/.DS_Store new file mode 100644 index 0000000..5008ddf Binary files /dev/null and b/data/.DS_Store differ diff --git a/data/.Rapp.history b/data/.Rapp.history new file mode 100644 index 0000000..2492ca8 --- /dev/null +++ b/data/.Rapp.history @@ -0,0 +1 @@ +load("/Users/jyk43/methylCIPHER/data/CalcGrimAgeV1.rda") diff --git a/data/CalcGrimAgeV1.rda b/data/CalcGrimAgeV1.rda new file mode 100644 index 0000000..e9cd41e Binary files /dev/null and b/data/CalcGrimAgeV1.rda differ diff --git a/data/CalcGrimAgeV2.rda b/data/CalcGrimAgeV2.rda new file mode 100644 index 0000000..ba49b9d Binary files /dev/null and b/data/CalcGrimAgeV2.rda differ diff --git a/data/GrimAge1_CpGs.rda b/data/GrimAge1_CpGs.rda new file mode 100644 index 0000000..e87192b Binary files /dev/null and b/data/GrimAge1_CpGs.rda differ diff --git a/data/GrimAge2_CpGs.rda b/data/GrimAge2_CpGs.rda new file mode 100644 index 0000000..c596f28 Binary files /dev/null and b/data/GrimAge2_CpGs.rda differ diff --git a/data/PCClocks_CpGs.rda b/data/PCClocks_CpGs.rda new file mode 100644 index 0000000..87a021b Binary files /dev/null and b/data/PCClocks_CpGs.rda differ diff --git a/man/calcAlcoholMcCartney.Rd b/man/calcAlcoholMcCartney.Rd index cc5de33..d697ece 100644 --- a/man/calcAlcoholMcCartney.Rd +++ b/man/calcAlcoholMcCartney.Rd @@ -4,7 +4,7 @@ \alias{calcAlcoholMcCartney} \title{calcAlcoholMcCartney} \usage{ -calcAlcoholMcCartney(DNAm, pheno = NULL, CpGImputation = NULL, imputation = F) +calcAlcoholMcCartney(DNAm, pheno = NULL, CpGImputation = NULL, imputation = T) } \arguments{ \item{DNAm}{a matrix of methylation beta values. Needs to be rows = samples and columns = CpGs, with rownames and colnames.} @@ -22,5 +22,5 @@ If you added the optional pheno input (preferred) the function appends a column A function to calculate the McCartney predictor of Alcohol } \examples{ -calcAlcoholMcCartney(exampleBetas, examplePheno, imputation = F) +calcAlcoholMcCartney(exampleBetas, examplePheno, imputation = T) } diff --git a/man/calcBMIMcCartney.Rd b/man/calcBMIMcCartney.Rd index bf8341c..60e74fb 100644 --- a/man/calcBMIMcCartney.Rd +++ b/man/calcBMIMcCartney.Rd @@ -4,7 +4,7 @@ \alias{calcBMIMcCartney} \title{calcBMIMcCartney} \usage{ -calcBMIMcCartney(DNAm, pheno = NULL, CpGImputation = NULL, imputation = F) +calcBMIMcCartney(DNAm, pheno = NULL, CpGImputation = NULL, imputation = T) } \arguments{ \item{DNAm}{a matrix of methylation beta values. Needs to be rows = samples and columns = CpGs, with rownames and colnames.} @@ -22,5 +22,5 @@ If you added the optional pheno input (preferred) the function appends a column A function to calculate the McCartney predictor of BMI } \examples{ -calcBMIMcCartney(exampleBetas, examplePheno, imputation = F) +calcBMIMcCartney(exampleBetas, examplePheno, imputation = T) } diff --git a/man/calcBocklandt.Rd b/man/calcBocklandt.Rd index be2b617..2767825 100644 --- a/man/calcBocklandt.Rd +++ b/man/calcBocklandt.Rd @@ -4,7 +4,7 @@ \alias{calcBocklandt} \title{calcBocklandt} \usage{ -calcBocklandt(DNAm, pheno = NULL, CpGImputation = NULL, imputation = F) +calcBocklandt(DNAm, pheno = NULL, CpGImputation = NULL, imputation = T) } \arguments{ \item{DNAm}{a matrix of methylation beta values. Needs to be rows = samples and columns = CpGs, with rownames and colnames.} @@ -22,5 +22,5 @@ If you added the optional pheno input (preferred) the function appends a column A function to calculate the Bocklandt clock. } \examples{ -calcBocklandt(exampleBetas, examplePheno, imputation = F) +calcBocklandt(exampleBetas, examplePheno, imputation = T) } diff --git a/man/calcBohlin.Rd b/man/calcBohlin.Rd index 253032c..66d126f 100644 --- a/man/calcBohlin.Rd +++ b/man/calcBohlin.Rd @@ -4,7 +4,7 @@ \alias{calcBohlin} \title{calcBohlin} \usage{ -calcBohlin(DNAm, pheno = NULL, CpGImputation = NULL, imputation = F) +calcBohlin(DNAm, pheno = NULL, CpGImputation = NULL, imputation = T) } \arguments{ \item{DNAm}{a matrix of methylation beta values. Needs to be rows = samples and columns = CpGs, with rownames and colnames.} @@ -22,5 +22,5 @@ If you added the optional pheno input (preferred) the function appends a column A function to calculate the Bohlin Gestational Age clock } \examples{ -calcBohlin(exampleBetas, examplePheno, imputation = F) +calcBohlin(exampleBetas, examplePheno, imputation = T) } diff --git a/man/calcClockCategory.Rd b/man/calcClockCategory.Rd index c62b047..9d6c2c0 100644 --- a/man/calcClockCategory.Rd +++ b/man/calcClockCategory.Rd @@ -2,14 +2,14 @@ % Please edit documentation in R/calcClockCategory.R \name{calcClockCategory} \alias{calcClockCategory} -\title{calcCoreClocks} +\title{calcClockCategory} \usage{ calcClockCategory( DNAm, pheno, category = NULL, CpGImputation = NULL, - imputation = F + imputation = T ) } \arguments{ @@ -32,5 +32,5 @@ NA } \examples{ -calcClockCategory(exampleBetas, examplePheno, category = "chronological", imputation = F) +calcClockCategory(exampleBetas, examplePheno, category = "chronological", imputation = T) } diff --git a/man/calcCoreClocks.Rd b/man/calcCoreClocks.Rd index f04d7f2..539cdf8 100644 --- a/man/calcCoreClocks.Rd +++ b/man/calcCoreClocks.Rd @@ -4,7 +4,7 @@ \alias{calcCoreClocks} \title{calcCoreClocks} \usage{ -calcCoreClocks(DNAm, pheno, CpGImputation = NULL, imputation = F) +calcCoreClocks(DNAm, pheno, CpGImputation = NULL, imputation = T) } \arguments{ \item{DNAm}{a matrix of methylation beta values. Needs to be rows = samples and columns = CpGs, with rownames and colnames.} @@ -22,5 +22,5 @@ A dataframe that has column names of the core clocks giving you multiple clocks A function to calculate the core, most utilized epigenetic clocks in the literature. } \examples{ -calcCoreClocks(exampleBetas, examplePheno, imputation = F) +calcCoreClocks(exampleBetas, examplePheno, imputation = T) } diff --git a/man/calcDNAmClockCortical.Rd b/man/calcDNAmClockCortical.Rd index 4e9f7a2..c777e0e 100644 --- a/man/calcDNAmClockCortical.Rd +++ b/man/calcDNAmClockCortical.Rd @@ -4,7 +4,7 @@ \alias{calcDNAmClockCortical} \title{calcDNAmClockCortical} \usage{ -calcDNAmClockCortical(DNAm, pheno = NULL, CpGImputation = NULL, imputation = F) +calcDNAmClockCortical(DNAm, pheno = NULL, CpGImputation = NULL, imputation = T) } \arguments{ \item{DNAm}{a matrix of methylation beta values. Needs to be rows = samples and columns = CpGs, with rownames and colnames.} @@ -22,6 +22,6 @@ If you added the optional pheno input (preferred) the function appends a column A function to calculate PhenoAge as retrained using HRS and InChianti data. Trained by Albert Higgins-Chen during the PC Clocks paper work. } \examples{ -calcDNAmClockCortical(exampleBetas, examplePheno, imputation = F) +calcDNAmClockCortical(exampleBetas, examplePheno, imputation = T) calcDNAmClockCortical(exampleBetas, examplePheno, CpGImputation = DNAmClockCortical_imputeRef, imputation = T) # Imputation in the case that there are missing CpGs using the original Brain Imputation from authors } diff --git a/man/calcDNAmTL.Rd b/man/calcDNAmTL.Rd index bc89c00..2f5ab08 100644 --- a/man/calcDNAmTL.Rd +++ b/man/calcDNAmTL.Rd @@ -4,7 +4,7 @@ \alias{calcDNAmTL} \title{calcDNAmTL} \usage{ -calcDNAmTL(DNAm, pheno = NULL, CpGImputation = NULL, imputation = F) +calcDNAmTL(DNAm, pheno = NULL, CpGImputation = NULL, imputation = T) } \arguments{ \item{DNAm}{a matrix of methylation beta values. Needs to be rows = samples and columns = CpGs, with rownames and colnames.} @@ -22,5 +22,5 @@ If you added the optional pheno input (preferred) the function appends a column A function to calculate the DNAmTL epigenetic clock } \examples{ -calcDNAmTL(exampleBetas, examplePheno, imputation = F) +calcDNAmTL(exampleBetas, examplePheno, imputation = T) } diff --git a/man/calcDunedinPoAm38.Rd b/man/calcDunedinPoAm38.Rd index 168f2e4..c5b6d09 100644 --- a/man/calcDunedinPoAm38.Rd +++ b/man/calcDunedinPoAm38.Rd @@ -25,5 +25,5 @@ If you added the optional pheno input (preferred) the function appends a column A function to calculate the Dunedin Pace of Aging Measure (DunedinPoAm38). This accesses the library available at github.com/danbelsky/DunedinPoAm38 } \examples{ -calcDunedinPoAm38(exampleBetas, examplePheno, imputation = F) +calcDunedinPoAm38(exampleBetas, examplePheno, imputation = T) } diff --git a/man/calcEpiTOC.Rd b/man/calcEpiTOC.Rd index cbb9ddc..4a9e68a 100644 --- a/man/calcEpiTOC.Rd +++ b/man/calcEpiTOC.Rd @@ -25,5 +25,5 @@ If you added the optional pheno input (preferred) the function appends a column A function to calculate the Epigenetic Timer of Cancer (EpiTOC) } \examples{ -calcEpiTOC(exampleBetas, examplePheno, imputation = F) +calcEpiTOC(exampleBetas, examplePheno, imputation = T) } diff --git a/man/calcEpiTOC2.Rd b/man/calcEpiTOC2.Rd index f605ee7..c3c60d3 100644 --- a/man/calcEpiTOC2.Rd +++ b/man/calcEpiTOC2.Rd @@ -31,5 +31,5 @@ If you added the optional pheno input (preferred) the function appends a column A function to calculate the Epigenetic Time of Cancer 2 (EpiTOC2) } \examples{ -calcEpiTOC2(exampleBetas, examplePheno, imputation = F) +calcEpiTOC2(exampleBetas, examplePheno, imputation = T) } diff --git a/man/calcGaragnani.Rd b/man/calcGaragnani.Rd index dd277c6..84f9149 100644 --- a/man/calcGaragnani.Rd +++ b/man/calcGaragnani.Rd @@ -4,7 +4,7 @@ \alias{calcGaragnani} \title{calcGaragnani} \usage{ -calcGaragnani(DNAm, pheno = NULL, CpGImputation = NULL, imputation = F) +calcGaragnani(DNAm, pheno = NULL, CpGImputation = NULL, imputation = T) } \arguments{ \item{DNAm}{a matrix of methylation beta values. Needs to be rows = samples and columns = CpGs, with rownames and colnames.} @@ -22,5 +22,5 @@ If you added the optional pheno input (preferred) the function appends a column A function to calculate the Garagnani single-CpG epigenetic clock } \examples{ -calcGaragnani(exampleBetas, examplePheno, imputation = F) +calcGaragnani(exampleBetas, examplePheno, imputation = T) } diff --git a/man/calcGrimAgeV1.Rd b/man/calcGrimAgeV1.Rd new file mode 100644 index 0000000..6788516 --- /dev/null +++ b/man/calcGrimAgeV1.Rd @@ -0,0 +1,31 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/calcGrimAgeV1.R +\name{calcGrimAgeV1} +\alias{calcGrimAgeV1} +\title{CalcGrimAgeV1} +\usage{ +calcGrimAgeV1(datMeth, datPheno) +} +\arguments{ +\item{DNAm}{a matrix of methylation beta values. Needs to be rows = samples and columns = CpGs, with rownames and colnames.} + +\item{pheno}{Optional: The sample phenotype data (also with samples as rows) that the clock will be appended to.} + +\item{CpGImputation}{An optional namesd vector for the mean value of each CpG that will be input from another dataset if such values are missing here (from sample cleaning)} + +\item{imputation}{Logical value that will allows you to perform (T)/ skip (F) imputation of mean values for missing CpGs. Warning: when imputation = F if there are missing CpGs, it will automatically ignore these CpGs during calculation, making the clock values less accurate.} +} +\value{ +If you added the optional pheno input (preferred) the function appends a column with the clock calculation and returns the dataframe. Otherwise, it will return a vector of calculated clock values in order of the +} +\description{ +A function to calculate GrimAgeV1 +} +\examples{ +CalcGrimAgeV1(exampleBetas, examplePheno, imputation = F) + + + + + +} diff --git a/man/calcGrimAgeV2.Rd b/man/calcGrimAgeV2.Rd new file mode 100644 index 0000000..9a6237c --- /dev/null +++ b/man/calcGrimAgeV2.Rd @@ -0,0 +1,24 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/calcGrimAgeV2.R +\name{calcGrimAgeV2} +\alias{calcGrimAgeV2} +\title{calcGrimAge2V2} +\usage{ +calcGrimAgeV2(datMeth, datPheno) +} +\arguments{ +\item{DNAm}{a matrix of methylation beta values. Needs to be rows = samples and columns = CpGs, with rownames and colnames.} + +\item{pheno}{Optional: The sample phenotype data (also with samples as rows) that the clock will be appended to.} +} +\value{ +If you added the optional pheno input (preferred) the function appends a column with the clock calculation and returns the dataframe. Otherwise, it will return a vector of calculated clock values in order of the +} +\description{ +A function to calculate GrimAgeV2 +} +\examples{ +calcPhenoAge(exampleBetas, examplePheno) + + +} diff --git a/man/calcHRSInChPhenoAge.Rd b/man/calcHRSInChPhenoAge.Rd index 15dbe12..b360f47 100644 --- a/man/calcHRSInChPhenoAge.Rd +++ b/man/calcHRSInChPhenoAge.Rd @@ -4,7 +4,7 @@ \alias{calcHRSInChPhenoAge} \title{calcHRSInChPhenoAge} \usage{ -calcHRSInChPhenoAge(DNAm, pheno = NULL, CpGImputation = NULL, imputation = F) +calcHRSInChPhenoAge(DNAm, pheno = NULL, CpGImputation = NULL, imputation = T) } \arguments{ \item{DNAm}{a matrix of methylation beta values. Needs to be rows = samples and columns = CpGs, with rownames and colnames.} @@ -22,5 +22,5 @@ If you added the optional pheno input (preferred) the function appends a column A function to calculate PhenoAge as retrained using HRS and InChianti data. Trained by Albert Higgins-Chen during the PC Clocks paper work. } \examples{ -calcHRSInChPhenoAge(exampleBetas, examplePheno, imputation = F) +calcHRSInChPhenoAge(exampleBetas, examplePheno, imputation = T) } diff --git a/man/calcHannum.Rd b/man/calcHannum.Rd index fcf7692..aebe76f 100644 --- a/man/calcHannum.Rd +++ b/man/calcHannum.Rd @@ -4,7 +4,7 @@ \alias{calcHannum} \title{calcHannum} \usage{ -calcHannum(DNAm, pheno = NULL, CpGImputation = NULL, imputation = F) +calcHannum(DNAm, pheno = NULL, CpGImputation = NULL, imputation = T) } \arguments{ \item{DNAm}{a matrix of methylation beta values. Needs to be rows = samples and columns = CpGs, with rownames and colnames.} @@ -22,5 +22,5 @@ If you added the optional pheno input (preferred) the function appends a column A function to calculate the Hannum epigenetic clock } \examples{ -calcHannum(exampleBetas, examplePheno, imputation = F) +calcHannum(exampleBetas, examplePheno, imputation = T) } diff --git a/man/calcHorvath1.Rd b/man/calcHorvath1.Rd index 8c5c3b3..ec94336 100644 --- a/man/calcHorvath1.Rd +++ b/man/calcHorvath1.Rd @@ -4,7 +4,7 @@ \alias{calcHorvath1} \title{calcHorvath1} \usage{ -calcHorvath1(DNAm, pheno = NULL, CpGImputation = NULL, imputation = F) +calcHorvath1(DNAm, pheno = NULL, CpGImputation = NULL, imputation = T) } \arguments{ \item{DNAm}{a matrix of methylation beta values. Needs to be rows = samples and columns = CpGs, with rownames and colnames.} @@ -22,5 +22,5 @@ If you added the optional pheno input (preferred) the function appends a column A function to calculate the Horvath Multi-Tissue epigenetic clock } \examples{ -calcHorvath1(exampleBetas, examplePheno, imputation = F) +calcHorvath1(exampleBetas, examplePheno, imputation = T) } diff --git a/man/calcHorvath2.Rd b/man/calcHorvath2.Rd index 4bca3a1..002adb6 100644 --- a/man/calcHorvath2.Rd +++ b/man/calcHorvath2.Rd @@ -4,7 +4,7 @@ \alias{calcHorvath2} \title{calcHorvath2} \usage{ -calcHorvath2(DNAm, pheno = NULL, CpGImputation = NULL, imputation = F) +calcHorvath2(DNAm, pheno = NULL, CpGImputation = NULL, imputation = T) } \arguments{ \item{DNAm}{a matrix of methylation beta values. Needs to be rows = samples and columns = CpGs, with rownames and colnames.} @@ -22,5 +22,5 @@ If you added the optional pheno input (preferred) the function appends a column A function to calculate the Horvath Skin & Blood epigenetic clock } \examples{ -calcHorvath2(exampleBetas, examplePheno, imputation = F) +calcHorvath2(exampleBetas, examplePheno, imputation = T) } diff --git a/man/calcHypoClock.Rd b/man/calcHypoClock.Rd index 636d665..098bb97 100644 --- a/man/calcHypoClock.Rd +++ b/man/calcHypoClock.Rd @@ -7,7 +7,7 @@ } \usage{ -calcHypoClock(DNAm, pheno = NULL, CpGImputation = NULL, imputation = F) +calcHypoClock(DNAm, pheno = NULL, CpGImputation = NULL, imputation = T) } \arguments{ \item{DNAm}{a matrix of methylation beta values. Needs to be rows = samples and columns = CpGs, with rownames and colnames.} @@ -25,5 +25,5 @@ If you added the optional pheno input (preferred) the function appends a column A function to calculate the HypoClock } \examples{ -calcHypoClock(exampleBetas, examplePheno, imputation = F) +calcHypoClock(exampleBetas, examplePheno, imputation = T) } diff --git a/man/calcKnight.Rd b/man/calcKnight.Rd index 8185efb..31bf588 100644 --- a/man/calcKnight.Rd +++ b/man/calcKnight.Rd @@ -4,7 +4,7 @@ \alias{calcKnight} \title{calcKnight} \usage{ -calcKnight(DNAm, pheno = NULL, CpGImputation = NULL, imputation = F) +calcKnight(DNAm, pheno = NULL, CpGImputation = NULL, imputation = T) } \arguments{ \item{DNAm}{a matrix of methylation beta values. Needs to be rows = samples and columns = CpGs, with rownames and colnames.} @@ -22,5 +22,5 @@ If you added the optional pheno input (preferred) the function appends a column A function to calculate the Knight gestational age } \examples{ -calcKnight(exampleBetas, examplePheno, imputation = F) +calcKnight(exampleBetas, examplePheno, imputation = T) } diff --git a/man/calcLeeControl.Rd b/man/calcLeeControl.Rd index c2bf2ea..56a42d0 100644 --- a/man/calcLeeControl.Rd +++ b/man/calcLeeControl.Rd @@ -4,7 +4,7 @@ \alias{calcLeeControl} \title{calcLeeControl} \usage{ -calcLeeControl(DNAm, pheno = NULL, CpGImputation = NULL, imputation = F) +calcLeeControl(DNAm, pheno = NULL, CpGImputation = NULL, imputation = T) } \arguments{ \item{DNAm}{a matrix of methylation beta values. Needs to be rows = samples and columns = CpGs, with rownames and colnames.} @@ -22,5 +22,5 @@ If you added the optional pheno input (preferred) the function appends a column A function to calculate the Predictor of Control Placental Age (Lee) } \examples{ -calcLeeControl(exampleBetas, examplePheno, imputation = F) +calcLeeControl(exampleBetas, examplePheno, imputation = T) } diff --git a/man/calcLeeRefinedRobust.Rd b/man/calcLeeRefinedRobust.Rd index 748a203..df4acd9 100644 --- a/man/calcLeeRefinedRobust.Rd +++ b/man/calcLeeRefinedRobust.Rd @@ -4,7 +4,7 @@ \alias{calcLeeRefinedRobust} \title{calcLeeRefinedRobust} \usage{ -calcLeeRefinedRobust(DNAm, pheno = NULL, CpGImputation = NULL, imputation = F) +calcLeeRefinedRobust(DNAm, pheno = NULL, CpGImputation = NULL, imputation = T) } \arguments{ \item{DNAm}{a matrix of methylation beta values. Needs to be rows = samples and columns = CpGs, with rownames and colnames.} @@ -22,5 +22,5 @@ If you added the optional pheno input (preferred) the function appends a column A function to calculate the Refined version of the Robust Predictor of Placental Age (Lee) } \examples{ -calcLeeRefinedRobust(exampleBetas, examplePheno, imputation = F) +calcLeeRefinedRobust(exampleBetas, examplePheno, imputation = T) } diff --git a/man/calcLeeRobust.Rd b/man/calcLeeRobust.Rd index 646c7fc..66e1246 100644 --- a/man/calcLeeRobust.Rd +++ b/man/calcLeeRobust.Rd @@ -4,7 +4,7 @@ \alias{calcLeeRobust} \title{calcLeeRobust} \usage{ -calcLeeRobust(DNAm, pheno = NULL, CpGImputation = NULL, imputation = F) +calcLeeRobust(DNAm, pheno = NULL, CpGImputation = NULL, imputation = T) } \arguments{ \item{DNAm}{a matrix of methylation beta values. Needs to be rows = samples and columns = CpGs, with rownames and colnames.} @@ -22,5 +22,5 @@ If you added the optional pheno input (preferred) the function appends a column A function to calculate the Robust Predictor of Placental Age (Lee) } \examples{ -calcLeeRobust(exampleBetas, examplePheno, imputation = F) +calcLeeRobust(exampleBetas, examplePheno, imputation = T) } diff --git a/man/calcLin.Rd b/man/calcLin.Rd index d59294c..3dea4ef 100644 --- a/man/calcLin.Rd +++ b/man/calcLin.Rd @@ -4,7 +4,7 @@ \alias{calcLin} \title{calcLin} \usage{ -calcLin(DNAm, pheno = NULL, CpGImputation = NULL, imputation = F) +calcLin(DNAm, pheno = NULL, CpGImputation = NULL, imputation = T) } \arguments{ \item{DNAm}{a matrix of methylation beta values. Needs to be rows = samples and columns = CpGs, with rownames and colnames.} @@ -22,5 +22,5 @@ If you added the optional pheno input (preferred) the function appends a column A function to calculate the Lin 99CpG Clock. } \examples{ -calcHRSInChPhenoAge(exampleBetas, examplePheno, imputation = F) +calcHRSInChPhenoAge(exampleBetas, examplePheno, imputation = T) } diff --git a/man/calcMayne.Rd b/man/calcMayne.Rd index f2b2bfd..217ab14 100644 --- a/man/calcMayne.Rd +++ b/man/calcMayne.Rd @@ -4,7 +4,7 @@ \alias{calcMayne} \title{calcMayne} \usage{ -calcMayne(DNAm, pheno = NULL, CpGImputation = NULL, imputation = F) +calcMayne(DNAm, pheno = NULL, CpGImputation = NULL, imputation = T) } \arguments{ \item{DNAm}{a matrix of methylation beta values. Needs to be rows = samples and columns = CpGs, with rownames and colnames.} @@ -22,6 +22,6 @@ If you added the optional pheno input (preferred) the function appends a column A function to calculate the Mayne Gestational Age predictor } \examples{ -calcMayne(exampleBetas, examplePheno, imputation = F) +calcMayne(exampleBetas, examplePheno, imputation = T) calcMayne(exampleBetas, examplePheno, imputation = T, CpGImputation = Mayne_impute) #For the Mayne imputation gold standard } diff --git a/man/calcMiAge.Rd b/man/calcMiAge.Rd index 60b6f55..a90e4ee 100644 --- a/man/calcMiAge.Rd +++ b/man/calcMiAge.Rd @@ -4,7 +4,7 @@ \alias{calcMiAge} \title{calcMiAge} \usage{ -calcMiAge(DNAm, pheno = NULL, CpGImputation = NULL, imputation = F) +calcMiAge(DNAm, pheno = NULL, CpGImputation = NULL, imputation = T) } \arguments{ \item{DNAm}{a matrix of methylation beta values. Needs to be rows = samples and columns = CpGs, with rownames and colnames.} @@ -22,5 +22,5 @@ If you added the optional pheno input (preferred) the function appends a column A function to calculate MiAge } \examples{ -calcMiAge(exampleBetas, examplePheno, imputation = F) +calcMiAge(exampleBetas, examplePheno, imputation = T) } diff --git a/man/calcPCClocks.Rd b/man/calcPCClocks.Rd new file mode 100644 index 0000000..13dcd82 --- /dev/null +++ b/man/calcPCClocks.Rd @@ -0,0 +1,24 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/calcPCClocks.R +\name{calcPCClocks} +\alias{calcPCClocks} +\title{calcPCClocks} +\usage{ +calcPCClocks(datMeth, datPheno) +} +\arguments{ +\item{DNAm}{a matrix of methylation beta values. Needs to be rows = samples and columns = CpGs, with rownames and colnames.} + +\item{pheno}{Optional: The sample phenotype data (also with samples as rows) that the clock will be appended to.} +} +\value{ +If you added the optional pheno input (preferred) the function appends a column with the clock calculation and returns the dataframe. Otherwise, it will return a vector of calculated clock values in order of the +} +\description{ +A function to calculate all PC Clocks +} +\examples{ +calcPhenoAge(exampleBetas, examplePheno) + + +} diff --git a/man/calcPEDBE.Rd b/man/calcPEDBE.Rd index fb20962..bb36c71 100644 --- a/man/calcPEDBE.Rd +++ b/man/calcPEDBE.Rd @@ -4,7 +4,7 @@ \alias{calcPEDBE} \title{calcPEDBE} \usage{ -calcPEDBE(DNAm, pheno = NULL, CpGImputation = NULL, imputation = F) +calcPEDBE(DNAm, pheno = NULL, CpGImputation = NULL, imputation = T) } \arguments{ \item{DNAm}{a matrix of methylation beta values. Needs to be rows = samples and columns = CpGs, with rownames and colnames.} @@ -22,5 +22,5 @@ If you added the optional pheno input (preferred) the function appends a column A function to calculate the PEDBE epigenetic clock } \examples{ -calcPEDBE(exampleBetas, examplePheno, imputation = F) +calcPEDBE(exampleBetas, examplePheno, imputation = T) } diff --git a/man/calcPhenoAge.Rd b/man/calcPhenoAge.Rd index 8fbc91e..3c18098 100644 --- a/man/calcPhenoAge.Rd +++ b/man/calcPhenoAge.Rd @@ -4,7 +4,7 @@ \alias{calcPhenoAge} \title{calcPhenoAge} \usage{ -calcPhenoAge(DNAm, pheno = NULL, CpGImputation = NULL, imputation = F) +calcPhenoAge(DNAm, pheno = NULL, CpGImputation = NULL, imputation = T) } \arguments{ \item{DNAm}{a matrix of methylation beta values. Needs to be rows = samples and columns = CpGs, with rownames and colnames.} @@ -22,5 +22,5 @@ If you added the optional pheno input (preferred) the function appends a column A function to calculate original 513 CpG PhenoAge } \examples{ -calcPhenoAge(exampleBetas, examplePheno, imputation = F) +calcPhenoAge(exampleBetas, examplePheno, imputation = T) } diff --git a/man/calcSmokingMcCartney.Rd b/man/calcSmokingMcCartney.Rd index c3d4087..a4f7a68 100644 --- a/man/calcSmokingMcCartney.Rd +++ b/man/calcSmokingMcCartney.Rd @@ -4,7 +4,7 @@ \alias{calcSmokingMcCartney} \title{calcSmokingMcCartney} \usage{ -calcSmokingMcCartney(DNAm, pheno = NULL, CpGImputation = NULL, imputation = F) +calcSmokingMcCartney(DNAm, pheno = NULL, CpGImputation = NULL, imputation = T) } \arguments{ \item{DNAm}{a matrix of methylation beta values. Needs to be rows = samples and columns = CpGs, with rownames and colnames.} @@ -22,5 +22,5 @@ If you added the optional pheno input (preferred) the function appends a column A function to calculate the McCartney predictor of Smoking } \examples{ -calcSmokingMcCartney(exampleBetas, examplePheno, imputation = F) +calcSmokingMcCartney(exampleBetas, examplePheno, imputation = T) } diff --git a/man/calcUserClocks.Rd b/man/calcUserClocks.Rd index 638dd78..4260e59 100644 --- a/man/calcUserClocks.Rd +++ b/man/calcUserClocks.Rd @@ -4,7 +4,7 @@ \alias{calcUserClocks} \title{calcUserClocks} \usage{ -calcUserClocks(clockList, DNAm, pheno, CpGImputation = NULL, imputation = F) +calcUserClocks(clockList, DNAm, pheno, CpGImputation = NULL, imputation = T) } \arguments{ \item{clockList}{A character vector of clock calculation functions the user would like to compute at once. Options can be found by running the function clockOptions()} @@ -25,5 +25,5 @@ A function to calculate multiple epigenetic clocks at once, as defined by the us } \examples{ userClocks <- c("calcSmokingMcCartney","calcPhenoAge","calcEpiTOC2") -calcUserClocks(userClocks, exampleBetas, examplePheno, imputation = F) +calcUserClocks(userClocks, exampleBetas, examplePheno, imputation = T) } diff --git a/man/calcVidalBralo.Rd b/man/calcVidalBralo.Rd index a97e70f..314c892 100644 --- a/man/calcVidalBralo.Rd +++ b/man/calcVidalBralo.Rd @@ -4,7 +4,7 @@ \alias{calcVidalBralo} \title{calcVidalBralo} \usage{ -calcVidalBralo(DNAm, pheno = NULL, CpGImputation = NULL, imputation = F) +calcVidalBralo(DNAm, pheno = NULL, CpGImputation = NULL, imputation = T) } \arguments{ \item{DNAm}{a matrix of methylation beta values. Needs to be rows = samples and columns = CpGs, with rownames and colnames.} @@ -22,5 +22,5 @@ If you added the optional pheno input (preferred) the function appends a column A function to calculate the Vidal-Bralo clock. } \examples{ -calcVidalBralo(exampleBetas, examplePheno, imputation = F) +calcVidalBralo(exampleBetas, examplePheno, imputation = T) } diff --git a/man/calcWeidner.Rd b/man/calcWeidner.Rd index da8cb68..6767625 100644 --- a/man/calcWeidner.Rd +++ b/man/calcWeidner.Rd @@ -4,7 +4,7 @@ \alias{calcWeidner} \title{calcWeidner} \usage{ -calcWeidner(DNAm, pheno = NULL, CpGImputation = NULL, imputation = F) +calcWeidner(DNAm, pheno = NULL, CpGImputation = NULL, imputation = T) } \arguments{ \item{DNAm}{a matrix of methylation beta values. Needs to be rows = samples and columns = CpGs, with rownames and colnames.} @@ -22,5 +22,5 @@ If you added the optional pheno input (preferred) the function appends a column A function to calculate the Weidner clock } \examples{ -calcWeidner(exampleBetas, examplePheno, imputation = F) +calcWeidner(exampleBetas, examplePheno, imputation = T) } diff --git a/man/calcZhang.Rd b/man/calcZhang.Rd index c2bb07f..4156f9b 100644 --- a/man/calcZhang.Rd +++ b/man/calcZhang.Rd @@ -4,7 +4,7 @@ \alias{calcZhang} \title{calcZhang} \usage{ -calcZhang(DNAm, pheno = NULL, CpGImputation = NULL, imputation = F) +calcZhang(DNAm, pheno = NULL, CpGImputation = NULL, imputation = T) } \arguments{ \item{DNAm}{a matrix of methylation beta values. Needs to be rows = samples and columns = CpGs, with rownames and colnames.} @@ -22,5 +22,5 @@ If you added the optional pheno input (preferred) the function appends a column A function to calculate the Zhang epigenetic clock } \examples{ -calcZhang(exampleBetas, examplePheno, imputation = F) +calcZhang(exampleBetas, examplePheno, imputation = T) } diff --git a/man/calcZhang2019.Rd b/man/calcZhang2019.Rd index 8af5c58..c18611c 100644 --- a/man/calcZhang2019.Rd +++ b/man/calcZhang2019.Rd @@ -4,7 +4,7 @@ \alias{calcZhang2019} \title{calcZhang2019} \usage{ -calcZhang2019(DNAm, pheno = NULL, CpGImputation = NULL, imputation = F) +calcZhang2019(DNAm, pheno = NULL, CpGImputation = NULL, imputation = T) } \arguments{ \item{DNAm}{a matrix of methylation beta values. Needs to be rows = samples and columns = CpGs, with rownames and colnames.} @@ -22,5 +22,5 @@ If you added the optional pheno input (preferred) the function appends a column A function to calculate the Zhang 2019, ultra-precise age measure } \examples{ -calcZhang2019(exampleBetas, examplePheno, imputation = F) +calcZhang2019(exampleBetas, examplePheno, imputation = T) }