% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/fcommon.R
\name{fcommon}
\alias{fcommon}
\title{Fast Identify Common Substrings In A Pair Of Strings}
\usage{
fcommon(x, y)
}
\arguments{
\item{x, y}{character, length 1 each: a string, such as a protein chain. \code{y} can be missing}
}
\value{
A sorted character vector of common substrings of length >= 2 characters each. When \code{y} is missing from call, a sorted
character vector of valid substrings in \code{x} of length >= 2 characters each.
}
\description{
Checks and identifies substrings that are common to a pair of strings.
}
\details{
This utility identifies common substrings in the \code{x}, \code{y} pair of strings by isolating \emph{sequences} of
identical characters in both strings which then, are packed into substrings and validated. All one-character substrings are removed.
When \code{y} is missing, \code{x} is cleaved at each letter producing all substrings longer than 2 characters.
}
\examples{

if (interactive()) {

 # 1. Check for common substrings in the pair below

 x = 'dvvmtqsplslpvtpgepasiscrssqslaktyrvvsvltvlhqdwlngkeykckvv'
 y = 'mtqspltyrvvsvltvlhqdwlngkeykcksnkalpapiektisk'

# 1.1 Common substrings
 system.time(a <- fcommon(x, y))
 print(head(a, 30))

# 1.2 Cleaving (slow on very long strings!)
 system.time(aa <- fcommon(x))
 system.time(bb <- fcommon(y))

# 1.3 Identical results
 A = sort(intersect(aa, bb))                                # common substrings
 identical(a, A)                                            # TRUE

# 2. Different methods for valid substrings

x = 'tyrvvsvltvlhqdwlngkeykck'

# 2.1. Combinations matrix (slower!)
system.time(am <- cover(x, valid. = TRUE))                  # valid substrings

# 2.2 String cleaving
system.time(ac <- fcommon(x))                               # valid substrings

identical(am, ac)                                           # TRUE

}

}
\seealso{
\link{cover}
}
\keyword{Proteomics}
