% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/preprocessingPheno.R
\name{preprocessingPheno}
\alias{preprocessingPheno}
\title{Prepare phenotype and methylation matrices for downstream modeling}
\usage{
preprocessingPheno(
  phenoFile = "data/preprocessingMinfiEwasWater/phenoLC.csv",
  sepType = NULL,
  betaPath =
    "rData/preprocessingMinfiEwasWater/metrics/beta_NomFilt_MSetF_Flt_Rxy_Ds_Rc.RData",
  mPath = "rData/preprocessingMinfiEwasWater/metrics/m_NomFilt_MSetF_Flt_Rxy_Ds_Rc.RData",
  cnPath =
    "rData/preprocessingMinfiEwasWater/metrics/cn_NomFilt_MSetF_Flt_Rxy_Ds_Rc.RData",
  SampleID = "Sample_Name",
  timeVar = "Timepoint",
  timepoints = "1,2",
  combineTimepoints = "1,2",
  methylationScale = "beta",
  outputPheno = "data/preprocessingPheno",
  outputRData = "rData/preprocessingPheno/metrics",
  outputRDataMerge = "rData/preprocessingPheno/mergeData",
  sexColumn = "Sex",
  outputLogs = "logs",
  outputDir = "data/preprocessingPheno",
  verbose = FALSE,
  logs = FALSE,
  saveOutputs = FALSE
)
}
\arguments{
\item{phenoFile}{Character. Path to the phenotype CSV file.}

\item{sepType}{Character or \code{NULL}. Field separator used in \code{phenoFile}. Use
\code{NULL} for a comma-separated file, \code{'\\\\t'} for a tab-delimited file, or
another separator accepted by \code{utils::read.csv()}.}

\item{betaPath}{Character. Path to the saved beta-value object. Both \code{.RData}
and \code{.rds} files are supported.}

\item{mPath}{Character. Path to the saved M-value object. Both \code{.RData} and
\code{.rds} files are supported.}

\item{cnPath}{Character. Path to the saved copy-number object. Both \code{.RData}
and \code{.rds} files are supported.}

\item{SampleID}{Character. Name of the phenotype column containing sample
identifiers used to align phenotype and methylation data.}

\item{timeVar}{Character. Name of the phenotype column containing timepoint
labels.}

\item{timepoints}{Character vector or comma-separated string of timepoints to
retain and split into separate in-memory subsets.}

\item{combineTimepoints}{Character vector or comma-separated string of
timepoints to combine into the longitudinal phenotype-plus-methylation
object.}

\item{methylationScale}{Character. Methylation metric to use in merged
modeling tables. One of \code{'Beta'}, \code{'M'}, or \code{'CN'}, in any combination
of upper- and lower-case letters. The default is \code{'beta'}. Beta values
are always used for Clock Foundation exports.}

\item{outputPheno}{Character. Directory used for saved phenotype CSV files
when \code{saveOutputs = TRUE}.}

\item{outputRData}{Character. Directory used for saved metric \code{.RData} files
when \code{saveOutputs = TRUE}.}

\item{outputRDataMerge}{Character. Directory used for saved merged
phenotype-plus-methylation \code{.RData} files when \code{saveOutputs = TRUE}.}

\item{sexColumn}{Character. Name of the phenotype sex column used when
building Clock Foundation exports.}

\item{outputLogs}{Character. Directory used for log files when \code{logs = TRUE}.}

\item{outputDir}{Character. Directory used for Clock Foundation export files
when \code{saveOutputs = TRUE}.}

\item{verbose}{Logical. If \code{TRUE}, emit progress messages with \code{message()}.
The default is \code{FALSE}.}

\item{logs}{Logical. If \code{TRUE}, write the same progress messages to
\code{outputLogs}. The default is \code{FALSE}.}

\item{saveOutputs}{Logical. If \code{TRUE}, write the CSV, ZIP, and \code{.RData}
outputs to disk. The default is \code{FALSE}.}
}
\value{
A list with class \code{'dnaEPICO_preprocessingPheno'}.
\describe{
\item{pheno}{Phenotype table read from \code{phenoFile}.}
\item{metricsData}{Object returned by \code{\link[=loadMetricsPreprocessingPheno]{loadMetricsPreprocessingPheno()}}
containing the beta-value, M-value, and copy-number matrices loaded from
\code{betaPath}, \code{mPath}, and \code{cnPath}.}
\item{timepointData}{Object returned by
\code{\link[=splitTimepointsPreprocessingPheno]{splitTimepointsPreprocessingPheno()}}
containing per-timepoint phenotype tables and methylation matrices.}
\item{combinedData}{Object returned by
\code{\link[=combineTimepointsPreprocessingPheno]{combineTimepointsPreprocessingPheno()}} containing the merged longitudinal
phenotype-plus-methylation object and the timepoint combination metadata.}
\item{clockFoundation}{Object returned by
\code{\link[=buildClockFoundationInputsPreprocessingPheno]{buildClockFoundationInputsPreprocessingPheno()}} containing the beta table
and phenotype table prepared for Clock Foundation export.}
\item{savedFiles}{Object returned by \code{\link[=writePreprocessingPhenoOutputs]{writePreprocessingPhenoOutputs()}} when
\code{saveOutputs = TRUE}, otherwise \code{NULL}.}
\item{logFile}{Resolved path to the optional log file, or \code{NULL} when
logging was disabled.}
}
See \linkS4class{dnaEPICO_preprocessingPheno} for a class-level overview.
}
\description{
Read the phenotype table and the preprocessed beta, M-value, and copy-number
matrices; align them by sample identifier; split them by timepoint; prepare
combined longitudinal objects for a selected modeling scale; and build Clock
Foundation export tables. The
function returns a structured in-memory result, while files are
written only when \code{saveOutputs = TRUE}.
}
\examples{
tmp <- tempdir()
pheno <- data.frame(
    Sample_Name = c("S1", "S2", "S3"),
    Timepoint = c("1", "1", "2"),
    Sex = c(0, 1, 0),
    stringsAsFactors = FALSE
)
beta <- matrix(
    c(0.10, 0.20, 0.30, 0.40, 0.50, 0.60),
    nrow = 2,
    dimnames = list(c("cg1", "cg2"), pheno$Sample_Name)
)
m <- beta * 10
cn <- beta * 100
pheno_file <- file.path(tmp, "pheno.csv")
beta_path <- file.path(tmp, "beta.RData")
m_path <- file.path(tmp, "m.RData")
cn_path <- file.path(tmp, "cn.RData")
utils::write.csv(pheno, pheno_file, row.names = FALSE)
save(beta, file = beta_path)
save(m, file = m_path)
save(cn, file = cn_path)
result <- preprocessingPheno(
    phenoFile = pheno_file,
    betaPath = beta_path,
    mPath = m_path,
    cnPath = cn_path,
    SampleID = "Sample_Name",
    timeVar = "Timepoint",
    timepoints = "1,2",
    combineTimepoints = "1,2",
    outputPheno = file.path(tmp, "data", "preprocessingPheno"),
    outputRData = file.path(tmp, "rData", "preprocessingPheno", "metrics"),
    outputRDataMerge = file.path(tmp, "rData", "preprocessingPheno", "mergeData"),
    sexColumn = "Sex",
    outputLogs = file.path(tmp, "logs"),
    outputDir = file.path(tmp, "clockFoundation"),
    saveOutputs = FALSE
)
stopifnot(inherits(result, "dnaEPICO_preprocessingPheno"))

}
\seealso{
\linkS4class{dnaEPICO_preprocessingPheno}
}
