% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/QC.R
\name{applyQScoreModel}
\alias{applyQScoreModel}
\title{applyQScoreModel}
\usage{
applyQScoreModel(spe, qsModel, scoreName = "QScore")
}
\arguments{
\item{spe}{A `SpatialExperiment` object with QC metrics already computed.}

\item{qsModel}{A Quality Score model object, usually stored in
`metadata(spe)$QScore_model`.}

\item{scoreName}{Name of the output column in `colData`.}
}
\value{
A `SpatialExperiment` object with added Quality Score in `colData`.
}
\description{
Applies a previously trained Quality Score model to a new SpatialExperiment
object.
See details for important considerations when applying a model to a
different dataset.
}
\details{
The authors do not recommend applying a Quality Score (QS) model trained on one
dataset to a different dataset, but this could be useful in some cases,
for example to transfer a model trained on a dataset sourced from a tissue 
slide sample and then applied to other slides from the same experiment.
When transferring the model from a reference dataset of the same technology
of the query dataset, there is no need to set a common formula. However,
when transferring from a different technology, reference QS computation 
should be performed providing a formula that excludes untransferable or unwanted 
variables (e.g. computing QS on a reference CosMx dataset omitting the border 
effect term to transfer the QS model to a Xenium query dataset. This is done by
providing a custom formula in computeQScore, see link computeQScore). The function will check 
for the presence of required model variables in the new dataset and will handle 
missing or extra variables accordingly.
}
\examples{

example(readCosmxSPE)

## Compute per-cell quality control metrics
spe <- spatialPerCellQC(spe)

## Split the object only for example purposes
set.seed(1998)
idx <- sample(seq_len(ncol(spe)), floor(ncol(spe) / 2))
spe_train <- spe[, idx]
spe_test <- spe[, -idx]

## Train the Quality Control (QC) score model on one dataset
spe_train <- computeQScore(spe_train)
qs_model <- metadata(spe_train)$QScore_model

## Apply the trained model to another dataset
spe_test <- applyQScoreModel(
    spe=spe_test,
    qsModel=qs_model,
    scoreName="QScore_transferred"
)

summary(spe_test$QScore_transferred)
}
