% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/ConstructDNAmPanel.R
\name{ConstructDNAmPanel}
\alias{ConstructDNAmPanel}
\title{Construct DNA Methylation reference Panel}
\usage{
ConstructDNAmPanel(
  dnam.matrix,
  cell.types.info,
  panel.cell.types,
  n.probes = 100,
  fdr.threshold = 0.05,
  p.adjust.method = "BH",
  summary.method = "mean",
  equal.variance = FALSE
)
}
\arguments{
\item{dnam.matrix}{A DNA methylation beta value matrix with no NA values.
Rows should be Probe IDs and columns should be samples.}

\item{cell.types.info}{A data frame that must contain a 'CellType' column,
specifying the cell type for each sample in `dnam.matrix`.}

\item{panel.cell.types}{A character vector specifying for which cell types a
panel should be constructed. These must be present in
`cell.types.info$CellType`.}

\item{n.probes}{The number of top-ranked hypo-methylated probes to select for
each cell type. Default is 100.}

\item{fdr.threshold}{The FDR (False Discovery Rate) threshold for filtering
significantly differentially methylated probes. Default is 0.05.}

\item{p.adjust.method}{The method for multiple testing correction. Must be one of
the methods supported by `stats::p.adjust`. Default is "BH".}

\item{summary.method}{The method to use for summarizing methylation values when
creating the reference panel. Can be "mean" or "median".
Default is "mean".}

\item{equal.variance}{A logical value (`TRUE` or `FALSE`) passed to `genefilter::fastT`, 
indicating whether to assume equal variance between groups. Default is FALSE.}
}
\value{
A list containing two components:
        \item{DetailedResults}{A list where each element is a data frame for a
                               cell type in `panel.cell.types`. The data frame
                               contains detailed information for the selected probes,
                               such as GapScore, AbsEffectSize, Zstatistic, and Pvalue.}
        \item{ReferencePanel}{A matrix with probes as rows and cell types as columns.
                              The values are the mean or median methylation beta values
                              for each probe in the corresponding cell type. This can serve
                              as a reference matrix for deconvolution.}
}
\description{
Constructs a cell-type-specific DNA methylation panel by selecting
             top-ranked hypo-methylated probes based on a "Gap Specificity Score" metric,
             which prioritizes markers with large effect sizes.
}
\details{
The function's logic is as follows:
1. For each target cell type, it is compared against all other cell types.
2. A t-test is used to find differentially methylated probes, and p-values are
   adjusted to FDR using the specified `p.adjust.method`.
3. Probes are filtered based on the `fdr.threshold`.
4. Only probes that are hypo-methylated in the target cell type (negative t-statistic)
   are retained.
5. A "Gap specificity Score" is calculated for these probes (defined as the minimum beta value
   in other cell types minus the maximum beta value in the target cell type).
6. Probes are ranked by the Gap Score, and the top `n.probes` are selected.
7. Finally, the probes selected for all target cell types are combined to form the
   final panel, and the reference matrix is computed using the specified `summary.method`.
}
\examples{
\dontrun{
# Assuming you have referenceBetas_matrix_noNA and referenceCovars_df
# library(genefilter)
# library(stats)
# library(matrixStats)

# Define target cell types for the panel
target_cell_types <- c("CD4T", "Bcell", "Mono")

# Construct the Panel
panel_results <- ConstructDNAmPanel(
  dnam.matrix = referenceBetas_matrix_noNA,
  cell.types.info = referenceCovars_df,
  panel.cell.types = target_cell_types,
  n.probes = 50,
  fdr.threshold = 0.05,
  p.adjust.method = "BH",
  summary.method = "median" 
)

# View the results
# View the reference panel matrix
head(panel_results$ReferencePanel)

# View detailed probe info for B-cells
head(panel_results$DetailedResults$Bcell)
}
}
