% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/methods.R, R/methods_SE.R
\docType{methods}
\name{adjust_abundance}
\alias{adjust_abundance}
\alias{adjust_abundance,spec_tbl_df-method}
\alias{adjust_abundance,tbl_df-method}
\alias{adjust_abundance,tidybulk-method}
\alias{adjust_abundance,SummarizedExperiment-method}
\alias{adjust_abundance,RangedSummarizedExperiment-method}
\title{Adjust transcript abundance for unwanted variation}
\usage{
adjust_abundance(
  .data,
  .formula,
  .sample = NULL,
  .transcript = NULL,
  .abundance = NULL,
  transform = log1p,
  inverse_transform = expm1,
  action = "add",
  ...,
  log_transform = NULL
)

\S4method{adjust_abundance}{spec_tbl_df}(
  .data,
  .formula,
  .sample = NULL,
  .transcript = NULL,
  .abundance = NULL,
  transform = log1p,
  inverse_transform = expm1,
  action = "add",
  ...,
  log_transform = NULL
)

\S4method{adjust_abundance}{tbl_df}(
  .data,
  .formula,
  .sample = NULL,
  .transcript = NULL,
  .abundance = NULL,
  transform = log1p,
  inverse_transform = expm1,
  action = "add",
  ...,
  log_transform = NULL
)

\S4method{adjust_abundance}{tidybulk}(
  .data,
  .formula,
  .sample = NULL,
  .transcript = NULL,
  .abundance = NULL,
  transform = log1p,
  inverse_transform = expm1,
  action = "add",
  ...,
  log_transform = NULL
)

\S4method{adjust_abundance}{SummarizedExperiment}(
  .data,
  .formula,
  .sample = NULL,
  .transcript = NULL,
  .abundance = NULL,
  transform = log1p,
  inverse_transform = expm1,
  action = "add",
  ...,
  log_transform = NULL
)

\S4method{adjust_abundance}{RangedSummarizedExperiment}(
  .data,
  .formula,
  .sample = NULL,
  .transcript = NULL,
  .abundance = NULL,
  transform = log1p,
  inverse_transform = expm1,
  action = "add",
  ...,
  log_transform = NULL
)
}
\arguments{
\item{.data}{A `tbl` (with at least three columns for sample, feature and transcript abundance) or `SummarizedExperiment` (more convenient if abstracted to tibble with library(tidySummarizedExperiment))}

\item{.formula}{A formula with no response variable, representing the desired linear model where the first covariate is the factor of interest and the second covariate is the unwanted variation (of the kind ~ factor_of_interest + batch)}

\item{.sample}{The name of the sample column}

\item{.transcript}{The name of the transcript/gene column}

\item{.abundance}{The name of the transcript/gene abundance column}

\item{transform}{A function that will tranform the counts, by default it is log1p for RNA sequencing data, but for avoinding tranformation you can use identity}

\item{inverse_transform}{A function that is the inverse of transform (e.g. expm1 is inverse of log1p). This is needed to tranform back the counts after analysis.}

\item{action}{A character string. Whether to join the new information to the input tbl (add), or just get the non-redundant tbl with the new information (get).}

\item{...}{Further parameters passed to the function sva::ComBat}

\item{log_transform}{DEPRECATED - A boolean, whether the value should be log-transformed (e.g., TRUE for RNA sequencing data)}
}
\value{
A consistent object (to the input) with additional columns for the adjusted counts as `<COUNT COLUMN>_adjusted`

A consistent object (to the input) with additional columns for the adjusted counts as `<COUNT COLUMN>_adjusted`

A consistent object (to the input) with additional columns for the adjusted counts as `<COUNT COLUMN>_adjusted`

A consistent object (to the input) with additional columns for the adjusted counts as `<COUNT COLUMN>_adjusted`

A `SummarizedExperiment` object

A `SummarizedExperiment` object
}
\description{
adjust_abundance() takes as input A `tbl` (with at least three columns for sample, feature and transcript abundance) or `SummarizedExperiment` (more convenient if abstracted to tibble with library(tidySummarizedExperiment)) and returns a consistent object (to the input) with an additional adjusted abundance column. This method uses scaled counts if present.
}
\details{
`r lifecycle::badge("maturing")`

This function adjusts the abundance for (known) unwanted variation.
At the moment just an unwanted covariate is allowed at a time using Combat (DOI: 10.1093/bioinformatics/bts034)

Underlying method:
	sva::ComBat(data, batch = my_batch,	mod = design,	prior.plots = FALSE, ...)
}
\examples{



cm = tidybulk::se_mini
cm$batch = 0
cm$batch[colnames(cm) \%in\% c("SRR1740035", "SRR1740043")] = 1

 cm \%>\%
 identify_abundant() |>
	adjust_abundance(	~ condition + batch	)


}
