% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/sex_stratified_analysis_bulk.R
\name{sex_stratified_analysis_bulk}
\alias{sex_stratified_analysis_bulk}
\title{Perform differential expression analysis within each sex}
\usage{
sex_stratified_analysis_bulk(
  expression_data,
  sex,
  phenotype,
  sex_labels_vector = c("F", "M"),
  phenotype_labels_vector = c("WT", "TG"),
  min_samples = 3,
  method = c("limma", "deseq2", "edger")
)
}
\arguments{
\item{expression_data}{A numeric matrix of expression data with features in rows
and samples in columns. For \code{method = "limma"}, this can be a normalized
log-expression matrix or a raw count matrix. For \code{method = "deseq2"} or
\code{method = "edger"}, this must be a raw (non-negative integer) count matrix.}

\item{sex}{A vector indicating sex for each sample.}

\item{phenotype}{A vector indicating phenotype labels for each sample.}

\item{sex_labels_vector}{A character vector of length two defining the labels for sex (e.g., c("F", "M")). The first element must correspond to "female" and the second to "male".}

\item{phenotype_labels_vector}{Character vector specifying phenotype levels. The
first element is the reference, the second the comparison; contrast = 2 - 1
(e.g. c("WT","TG")).}

\item{min_samples}{Integer. Minimum number of samples per group (default 3).}

\item{method}{Character. Differential expression method to use. One of
\code{"limma"} (default), \code{"deseq2"}, or \code{"edger"}.}
}
\value{
A list with three elements:
  \describe{
    \item{male_DEGs}{A data.frame of DE results for males.}
    \item{female_DEGs}{A data.frame of DE results for females.}
    \item{validation}{Output from \code{validate_input_bulk()}.}
  }
  Regardless of the method, each DEG data.frame contains the standardized
  columns \code{avg_log2FC}, \code{p_val}, \code{p_val_adj}, and \code{gene},
  with gene names as rownames. Additional method-specific columns (e.g.
  \code{baseMean} for DESeq2, \code{logCPM} for edgeR, \code{AveExpr} for limma)
  are retained for reference.
}
\description{
This function identifies differentially expressed genes between phenotype groups
separately for each sex using limma (default), DESeq2, or edgeR.
}
\details{
For each sex, the function subsets the data and fits the appropriate
  model:
  \itemize{
   \item \strong{limma}: Fits a linear model via \code{lmFit} + \code{eBayes}
      on the input matrix directly. Suitable for microarray, proteomics, or
      pre-normalized RNA-seq data. If raw RNA-seq counts are provided, the
      function automatically detects integer matrices and applies
      \code{limma-voom} internally with a warning. For full control, consider
      using \code{"edger"} or \code{"deseq2"} instead, or apply \code{voom}
      externally and pass the transformed data with
      \code{method = "limma"}.
    \item \strong{DESeq2}: Fits a negative binomial GLM via
      \code{DESeq2::DESeq()}. Requires raw integer counts. Performs internal
      normalization (median-of-ratios) and dispersion estimation.
    \item \strong{edgeR}: Fits a negative binomial GLM via
      \code{edgeR::glmQLFit()} + \code{edgeR::glmQLFTest()}. Requires raw
      integer counts. Performs TMM normalization internally.
  }
  Positive logFC values indicate higher expression in the test phenotype
  (second element of \code{phenotype_labels_vector}) compared to the reference
  (first element).
}
