% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/diff_utils.R
\name{diff_expr}
\alias{diff_expr}
\title{Differential expression analysis of esets.}
\usage{
diff_expr(esets, data_dir = getwd(), annot = "SYMBOL",
  prev_anals = list(NULL), svanal = TRUE)
}
\arguments{
\item{esets}{List of annotated esets. Created by \code{\link{load_raw}}.}

\item{data_dir}{String specifying directory of GSE folders.}

\item{annot}{String, column name in fData common to all esets. For duplicated
values in this column, the row with the highest interquartile range
across selected samples will be kept. If meta-analysis will follow, appropriate
values are "SYMBOL" (default - for gene level analysis) or, if all esets are
from the same platform, "PROBE" (for probe level analysis).}

\item{prev_anals}{Previous result of \code{\link{diff_expr}}, which can
 be reloaded using \code{\link{load_diff}}. If present, previous
selections, names, and pairs will be reused.}

\item{svanal}{Use surrogate variable analysis? Default is \code{TRUE}.}
}
\value{
List of named lists, one for each GSE. Each named list contains:
  \item{pdata}{data.frame with phenotype data for selected samples.
     Columns \code{treatment} ('ctrl' or 'test'), \code{group}, and \code{pairs} are
     added based on user selections.}
  \item{top_tables}{List with results of \code{\link[limma]{topTable}} call (one per
     contrast). These results account for the effects of nuissance variables
     discovered by surrogate variable analysis.}
  \item{ebayes_sv}{Results of call to \code{\link[limma]{eBayes}} with surrogate
     variables included in the model matrix.}
  \item{annot}{Value of \code{annot} variable.}
}
\description{
After selecting control and test samples for each contrast, surrogate variable
analysis (\code{\link[sva]{sva}}) and differential expression analysis is performed.
}
\details{
The \strong{Samples} tab is used to select control and test samples for
each contrast. To do so: select rows for control samples, type a group name
in the \emph{Control group name} text input box and click the \emph{Add Group}
button. Repeat for test samples. While adding additional contrasts, a previous
control group can be quickly reselected from the \emph{Previous selections}
dropdown box. After control and test samples have been added for all contrasts
that you wish to include, click the \emph{Done} button. Repeat for all GSEs.

Paired samples (e.g. the same subject before and after treatment) can be
specified by selecting sample rows to pair and then clicking \emph{Pair Samples}.
The author does not usually specify paired samples and instead allows surrogate
variable analysis to discover these inter-sample relationships from the data itself.

The \strong{Contrasts} tab is used to view and delete contrasts that have
already been added.

For each GSE, analysis results are saved in the corresponding GSE
folder in \code{data_dir} that was created by \code{\link{get_raw}}. If analyses
needs to be repeated, previous results can be reloaded with \code{\link{load_diff}}
and supplied to the \code{prev_anals} parameter. In this case, previous
selections, names, and pairs will be reused.
}
\examples{
library(lydata)

# location of raw data
data_dir <- system.file("extdata", package = "lydata")

# gather GSE names
gse_names  <- c("GSE9601", "GSE15069", "GSE50841", "GSE34817", "GSE29689")

# load first eset
esets <- load_raw(gse_names[1], data_dir)

# run analysis
# anals <- diff_expr(esets, data_dir)

# re-run analysis on first eset
prev <- load_diff(gse_names[1], data_dir)
# anals <- diff_expr(esets[1], data_dir, prev_anals = prev)
}
