Package: ape
Version: 3.0-7
-Date: 2012-11-22
+Date: 2012-11-28
Title: Analyses of Phylogenetics and Evolution
Author: Emmanuel Paradis, Ben Bolker, Julien Claude, Hoa Sien Cuong, Richard Desper, Benoit Durand, Julien Dutheil, Olivier Gascuel, Christoph Heibl, Daniel Lawson, Vincent Lefort, Pierre Legendre, Jim Lemon, Yvonnick Noel, Johan Nylander, Rainer Opgen-Rhein, Andrei-Alin Popescu, Klaus Schliep, Korbinian Strimmer, Damien de Vienne
Maintainer: Emmanuel Paradis <Emmanuel.Paradis@ird.fr>
NEW FEATURES
+ o The new function 'where' searches patterns in DNA sequences.
+
o pic() gains an option 'rescaled.tree = FALSE' to return the tree
with its branch lengths rescaled for the PICs calculation.
-## DNA.R (2012-09-13)
+## DNA.R (2012-11-28)
## Manipulations and Comparisons of DNA Sequences
horiz = TRUE, xpd = TRUE)
}
}
+
+where <- function(x, pattern)
+{
+ pat <- as.DNAbin(strsplit(pattern, NULL)[[1]])
+ p <- as.integer(length(pat))
+
+ foo <- function(x, pat, p) {
+ s <- as.integer(length(x))
+ if (s < p) stop("sequence shorter than the pattern")
+ ans <- .C("where", x, pat, s, p, integer(s), 0L,
+ DUP = FALSE, NAOK = TRUE, PACKAGE = "apex")
+ n <- ans[[6]]
+ if (n) ans[[5]][seq_len(n)] - p + 2L else integer()
+ }
+
+ if (is.list(x)) return(lapply(x, foo, pat = pat, p = p))
+ if (is.matrix(x)) {
+ n <- nrow(x)
+ res <- vector("list", n)
+ for (i in seq_along(n))
+ res[[i]] <- foo(x[i, , drop = TRUE], pat, p)
+ names(res) <- rownames(x)
+ return(res)
+ }
+ foo(x, pat, p) # if x is a vector
+}
\value{
an object of class \code{"phylo"}.
}
+\references{
+ Felsenstein, J. (2004) \emph{Inferring Phylogenies}. Sunderland:
+ Sinauer Associates.
+}
\author{Emmanuel Paradis}
\seealso{
\code{\link{prop.part}}, \code{\link{dist.topo}}
--- /dev/null
+\names{where}
+\alias{where}
+\title{Find Patterns in DNA Sequences}
+\description{
+ This function finds patterns in a single or a set of DNA sequences.
+}
+\usage{
+where(x, pattern)
+}
+\arguments{
+ \item{x}{an object of class \code{"DNAbin"}.}
+ \item{pattern}{a character string to be searched in \code{x}.}
+}
+\details{
+ If \code{x} is a vector, the function returns a single vector giving
+ the position(s) where the pattern was found. If \code{x} is a matrix
+ or a list, it returns a list with the positions of the pattern for
+ each sequence.
+
+ Patterns may be overlapping. For instance, if \code{pattern = "tata"}
+ and the sequence starts with `tatata', then the vector returned will
+ be c(1, 3).
+}
+\value{
+ a vector of integers or a list of such vectors.
+}
+\author{Emmanuel Paradis}
+\seealso{
+ \code{\link{DNAbin}}, \code{\link{image.DNAbin}}
+}
+\examples{
+data(woodmouse)
+where(woodmouse, "tata")
+}
+\keyword{manip}
-/* dist_dna.c 2012-02-14 */
+/* dist_dna.c 2012-11-28 */
/* Copyright 2005-2012 Emmanuel Paradis
case 17 : distDNA_indelblock(x, n, s, d); break;
}
}
+
+void where(unsigned char *x, unsigned char *pat, int *s, int *p,
+ int *ans, int *n)
+{
+ int i, j, k, ln;
+
+ ln = 0; /* local n */
+
+ for (i = 0; i <= *s - *p; i++) {
+ k = i; j = 0;
+ while (1) {
+ if (x[k] != pat[j]) break;
+ j++; k++;
+ if (j == *p) {
+ ans[ln++] = k - 1;
+ break;
+ }
+ }
+ }
+ *n = ln;
+}