\HeaderA{matchLRPatterns}{Find paired matches in a sequence}{matchLRPatterns}
\aliasA{matchLRPatterns,MaskedXString-method}{matchLRPatterns}{matchLRPatterns,MaskedXString.Rdash.method}
\aliasA{matchLRPatterns,XString-method}{matchLRPatterns}{matchLRPatterns,XString.Rdash.method}
\aliasA{matchLRPatterns,XStringViews-method}{matchLRPatterns}{matchLRPatterns,XStringViews.Rdash.method}
\keyword{methods}{matchLRPatterns}
\begin{Description}\relax
The \code{matchLRPatterns} function finds paired matches in a sequence
i.e. matches specified by a left pattern, a right pattern and a maximum
distance between the left pattern and the right pattern.
\end{Description}
\begin{Usage}
\begin{verbatim}
  matchLRPatterns(Lpattern, Rpattern, max.gaplength, subject,
                  max.Lmismatch=0, max.Rmismatch=0,
                  with.Lindels=FALSE, with.Rindels=FALSE,
                  Lfixed=TRUE, Rfixed=TRUE)
\end{verbatim}
\end{Usage}
\begin{Arguments}
\begin{ldescription}
\item[\code{Lpattern}] The left part of the pattern.

\item[\code{Rpattern}] The right part of the pattern.

\item[\code{max.gaplength}] The max length of the gap in the middle i.e the max distance between
the left and right parts of the pattern.

\item[\code{subject}] An \LinkA{XString}{XString}, \LinkA{XStringViews}{XStringViews} or \LinkA{MaskedXString}{MaskedXString} object
containing the target sequence.

\item[\code{max.Lmismatch}] The maximum number of mismatching letters allowed in the left part of the
pattern.
If non-zero, an inexact matching algorithm is used (see the
\code{\LinkA{matchPattern}{matchPattern}} function for more information).

\item[\code{max.Rmismatch}] Same as \code{max.Lmismatch} but for the right part of the pattern.

\item[\code{with.Lindels}] If \code{TRUE} then indels are allowed in the left part of the pattern.
In that case \code{max.Lmismatch} is interpreted as the maximum "edit
distance" allowed in the left part of the pattern.

See the \code{with.indels} argument of the \code{\LinkA{matchPattern}{matchPattern}}
function for more information.

\item[\code{with.Rindels}] Same as \code{with.Lindels} but for the right part of the pattern.

\item[\code{Lfixed}] Only with a \LinkA{DNAString}{DNAString} or \LinkA{RNAString}{RNAString} subject can a
\code{Lfixed} value other than the default (\code{TRUE}) be used.

With \code{Lfixed=FALSE}, ambiguities (i.e. letters from the IUPAC
Extended Genetic Alphabet (see \code{\LinkA{IUPAC\_CODE\_MAP}{IUPAC.Rul.CODE.Rul.MAP}}) that
are not from the base alphabet) in the left pattern \_and\_ in the
subject are interpreted as wildcards i.e. they match any letter
that they stand for.

\code{Lfixed} can also be a character vector, a subset of
\code{c("pattern", "subject")}.
\code{Lfixed=c("pattern", "subject")} is equivalent to
\code{Lfixed=TRUE} (the default).
An empty vector is equivalent to \code{Lfixed=FALSE}.
With \code{Lfixed="subject"}, ambiguities in the pattern only are
interpreted as wildcards.
With \code{Lfixed="pattern"}, ambiguities in the subject only are
interpreted as wildcards.

\item[\code{Rfixed}] Same as \code{Lfixed} but for the right part of the pattern.

\end{ldescription}
\end{Arguments}
\begin{Value}
An \LinkA{XStringViews}{XStringViews} object containing all the matches, even when they are
overlapping (see the examples below), and where the matches are ordered
from left to right (i.e. by ascending starting position).
\end{Value}
\begin{Author}\relax
H. Pages
\end{Author}
\begin{SeeAlso}\relax
\code{\LinkA{matchPattern}{matchPattern}},
\code{\LinkA{matchProbePair}{matchProbePair}},
\code{\LinkA{trimLRPatterns}{trimLRPatterns}},
\code{\LinkA{findPalindromes}{findPalindromes}},
\code{\LinkA{reverseComplement}{reverseComplement}},
\LinkA{XString-class}{XString.Rdash.class},
\LinkA{XStringViews-class}{XStringViews.Rdash.class},
\LinkA{MaskedXString-class}{MaskedXString.Rdash.class}
\end{SeeAlso}
\begin{Examples}
\begin{ExampleCode}
  library(BSgenome.Dmelanogaster.UCSC.dm3)
  subject <- Dmelanogaster$chr3R
  Lpattern <- "AGCTCCGAG"
  Rpattern <- "TTGTTCACA"
  matchLRPatterns(Lpattern, Rpattern, 500, subject) # 1 match

  ## Note that matchLRPatterns() will return all matches, even when they are
  ## overlapping:
  subject <- DNAString("AAATTAACCCTT")
  matchLRPatterns("AA", "TT", 0, subject) # 1 match
  matchLRPatterns("AA", "TT", 1, subject) # 2 matches
  matchLRPatterns("AA", "TT", 3, subject) # 3 matches
  matchLRPatterns("AA", "TT", 7, subject) # 4 matches
\end{ExampleCode}
\end{Examples}

