\HeaderA{stringDist}{String Distance/Alignment Score Matrix}{stringDist}
\aliasA{stringDist,character-method}{stringDist}{stringDist,character.Rdash.method}
\aliasA{stringDist,QualityScaledXStringSet-method}{stringDist}{stringDist,QualityScaledXStringSet.Rdash.method}
\aliasA{stringDist,XStringSet-method}{stringDist}{stringDist,XStringSet.Rdash.method}
\keyword{character}{stringDist}
\keyword{multivariate}{stringDist}
\keyword{cluster}{stringDist}
\begin{Description}\relax
Computes the Levenshtein edit distance or pairwise alignment score matrix for a
set of strings.
\end{Description}
\begin{Usage}
\begin{verbatim}
stringDist(x, method = "levenshtein", ignoreCase = FALSE, diag = FALSE, upper = FALSE, ...)
## S4 method for signature 'XStringSet':
stringDist(x, method = "levenshtein", ignoreCase = FALSE, diag = FALSE,
                   upper = FALSE, type = "global", quality = PhredQuality(22L),
                   substitutionMatrix = NULL, fuzzyMatrix = NULL, gapOpening = 0,
                   gapExtension = -1)
## S4 method for signature 'QualityScaledXStringSet':
stringDist(x, method = "quality", ignoreCase = FALSE,
                   diag = FALSE, upper = FALSE, type = "global", substitutionMatrix = NULL,
                   fuzzyMatrix = NULL, gapOpening = 0, gapExtension = -1)
\end{verbatim}
\end{Usage}
\begin{Arguments}
\begin{ldescription}
\item[\code{x}] a character vector or an \code{\LinkA{XStringSet}{XStringSet}} object.
\item[\code{method}] calculation method. One of \code{"levenshtein"},
\code{"hamming"}, \code{"quality"}, or \code{"substitutionMatrix"}.
\item[\code{ignoreCase}] logical value indicating whether to ignore case during
scoring.
\item[\code{diag}] logical value indicating whether the diagonal of the matrix
should be printed by \code{print.dist}.
\item[\code{upper}] logical value indicating whether the upper triangle of the matrix
should be printed by \code{print.dist}.
\item[\code{type}] (applicable when \code{method = "quality"} or
\code{method = "substitutionMatrix"}).
type of alignment. One of \code{"global"}, \code{"local"}, and
\code{"overlap"}, where
\code{"global"} = align whole strings with end gap penalties,
\code{"local"} = align string fragments,
\code{"overlap"} = align whole strings without end gap penalties.
\item[\code{quality}] (applicable when \code{method = "quality"}).
object of class \code{\LinkA{XStringQuality}{XStringQuality}} representing the quality scores
for \code{x} that are used in a quality-based method for generating a
substitution matrix.
\item[\code{substitutionMatrix}] (applicable when
\code{method = "substitutionMatrix"}).
symmetric matrix representing the fixed substitution scores in the
alignment.
\item[\code{fuzzyMatrix}] (applicable when \code{method = "quality"}).
fuzzy match matrix for quality-based alignments. It takes values between 0
and 1; where 0 is an unambiguous mismatch, 1 is an unambiguous match, and
values in between represent a fraction of "matchiness".
\item[\code{gapOpening}] (applicable when \code{method = "quality"} or
\code{method = "substitutionMatrix"}).
penalty for opening a gap in the alignment.
\item[\code{gapExtension}] (applicable when \code{method = "quality"} or
\code{method = "substitutionMatrix"}).
penalty for extending a gap in the alignment
\item[\code{...}] optional arguments to generic function to support additional
methods.
\end{ldescription}
\end{Arguments}
\begin{Details}\relax
When \code{method = "hamming"}, uses the underlying \code{neditStartingAt} code
to calculate the distances, where the Hamming distance is defined as the number
of substitutions between two strings of equal length. Otherwise, uses the
underlying \code{pairwiseAlignment} code to compute the distance/alignment
score matrix.
\end{Details}
\begin{Value}
Returns an object of class \code{"dist"}.
\end{Value}
\begin{Author}\relax
P. Aboyoun
\end{Author}
\begin{SeeAlso}\relax
\LinkA{dist}{dist},
\LinkA{agrep}{agrep},
\LinkA{pairwiseAlignment}{pairwiseAlignment},
\LinkA{substitution.matrices}{substitution.matrices}
\end{SeeAlso}
\begin{Examples}
\begin{ExampleCode}
  stringDist(c("lazy", "HaZy", "crAzY"))
  stringDist(c("lazy", "HaZy", "crAzY"), ignoreCase = TRUE)

  data(phiX174Phage)
  plot(hclust(stringDist(phiX174Phage), method = "single"))

  data(srPhiX174)
  stringDist(srPhiX174[1:4])
  stringDist(srPhiX174[1:4], method = "quality",
             quality = SolexaQuality(quPhiX174[1:4]),
             gapOpening = -10, gapExtension = -4)
\end{ExampleCode}
\end{Examples}

