% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/findMutualNN.R
\name{findMutualNN}
\alias{findMutualNN}
\title{Find mutual nearest neighbors}
\usage{
findMutualNN(
  data1,
  data2,
  k1,
  k2 = k1,
  BNPARAM = KmknnParam(),
  BPPARAM = SerialParam()
)
}
\arguments{
\item{data1}{A numeric matrix containing samples (e.g., cells) in the rows and variables/dimensions in the columns.}

\item{data2}{A numeric matrix like \code{data1} for another data set with the same variables/dimensions.}

\item{k1}{Integer scalar specifying the number of neighbors to search for in \code{data1}.}

\item{k2}{Integer scalar specifying the number of neighbors to search for in \code{data2}.}

\item{BNPARAM}{A \linkS4class{BiocNeighborParam} object specifying the neighbour search algorithm to use.}

\item{BPPARAM}{A \linkS4class{BiocParallelParam} object specifying how parallelization should be performed.}
}
\value{
A list containing the integer vectors \code{first} and \code{second}.
Corresponding entries in \code{first} and \code{second} specify a MNN pair of cells from \code{data1} and \code{data2}, respectively.
}
\description{
Find mutual nearest neighbors (MNN) across two data sets.
}
\details{
The concept of a MNN pair can be explained by considering cells in each of two data sets. 
For each cell in data set 1, the set of \code{k2} nearest cells in data set 2 is identified, based on the Euclidean distance in expression space.
For each cell in data set 2, the set of \code{k1} nearest cells in data set 1 is similarly identified.
Two cells in different batches are considered to be MNNs if each cell is in the other's set.
}
\examples{
B1 <- matrix(rnorm(10000), ncol=50) # Batch 1 
B2 <- matrix(rnorm(10000), ncol=50) # Batch 2
out <- findMutualNN(B1, B2, k1=20)
head(out$first)
head(out$second)

}
\seealso{
\code{\link{queryKNN}} for the underlying neighbor search code.

\code{\link{fastMNN}} and \code{\link{mnnCorrect}}, which call this function to identify MNNs.
}
\author{
Aaron Lun
}
