[adegenet-commits] r1055 - in pkg: R man
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Tue Nov 20 18:08:52 CET 2012
Author: jombart
Date: 2012-11-20 18:08:51 +0100 (Tue, 20 Nov 2012)
New Revision: 1055
Added:
pkg/man/mutations.Rd
Removed:
pkg/man/findMutations.Rd
Modified:
pkg/R/gengraph.R
pkg/R/mutations.R
pkg/man/gengraph.Rd
Log:
findMutations/graphMutations sorted
Modified: pkg/R/gengraph.R
===================================================================
--- pkg/R/gengraph.R 2012-11-20 12:01:26 UTC (rev 1054)
+++ pkg/R/gengraph.R 2012-11-20 17:08:51 UTC (rev 1055)
@@ -10,8 +10,7 @@
#############
## DEFAULT ##
#############
-gengraph.default <- function(x, cutoff=NULL, ngrp=NULL, computeAll=FALSE, plot=TRUE, show.graph=TRUE, col.pal=funky,
- truenames=TRUE, ...){
+gengraph.default <- function(x, cutoff=NULL, ngrp=NULL, computeAll=FALSE, plot=TRUE, show.graph=TRUE, col.pal=funky, truenames=TRUE, ...){
stop(paste("No method for objects of class",class(x)))
} # end gengraph.default
@@ -144,7 +143,7 @@
############
## GENIND ##
############
-gengraph.dist <- function(x, cutoff=NULL, ngrp=NULL, computeAll=FALSE, plot=TRUE, show.graph=TRUE, col.pal=funky, ...){
+gengraph.dist <- function(x, cutoff=NULL, ngrp=NULL, computeAll=FALSE, plot=TRUE, show.graph=TRUE, col.pal=funky, truenames=TRUE, ...){
## CHECKS ##
if(!require("igraph")) stop("igraph is required")
Modified: pkg/R/mutations.R
===================================================================
--- pkg/R/mutations.R 2012-11-20 12:01:26 UTC (rev 1054)
+++ pkg/R/mutations.R 2012-11-20 17:08:51 UTC (rev 1055)
@@ -9,8 +9,10 @@
UseMethod("findMutations")
}
+
+
## METHOD FOR DNABIN
-findMutations.DNAbin <- function(x, from=NULL, to=NULL, ...){
+findMutations.DNAbin <- function(x, from=NULL, to=NULL, allcomb=TRUE, ...){
## CHECKS ##
if(!require(ape)) stop("the ape package is needed")
if(!inherits(x,"DNAbin")) stop("x is not a DNAbin object")
@@ -36,12 +38,23 @@
}
## GET LIST OF PAIRS TO COMPARE ##
+ ## handle from/to as character
+ if(is.character(from)) from <- match(from, rownames(x))
+ if(is.character(to)) to <- match(to, rownames(x))
+
## handle NULL
if(is.null(from)) from <- 1:nrow(x)
if(is.null(to)) to <- 1:nrow(x)
## get pairs
- pairs <- expand.grid(from, to)
+ if(allcomb){
+ pairs <- expand.grid(to, from)[,2:1,drop=FALSE]
+ } else {
+ N <- max(length(from),length(to))
+ from <- rep(from, length=N)
+ to <- rep(to, length=N)
+ pairs <- cbind(from, to)
+ }
## remove unwanted comparisons
pairs <- pairs[pairs[,1]!=pairs[,2],,drop=FALSE]
@@ -69,12 +82,14 @@
UseMethod("graphMutations")
}
+
+
## METHOD FOR DNABIN
-graphMutations.DNAbin <- function(x, from=NULL, to=NULL, plot=TRUE, edge.curved=TRUE, ...){
+graphMutations.DNAbin <- function(x, from=NULL, to=NULL, allcomb=TRUE, plot=TRUE, curved.edges=TRUE, ...){
if(!require(igraph)) stop("igraph is required")
## GET MUTATIONS ##
- x <- findMutations(x, from=from, to=to)
+ x <- findMutations(x, from=from, to=to, allcomb=allcomb)
## GET GRAPH ##
from <- gsub("->.*","",names(x))
@@ -86,7 +101,7 @@
## SET ANNOTATIONS FOR THE BRANCHES ##
annot <- unlist(lapply(x, function(e) paste(e$short, collapse="\n")))
E(out)$label <- annot
- E(out)$curved <- edge.curved
+ E(out)$curved <- curved.edges
## PLOT / RETURN ##
if(plot) plot(out, ...)
Deleted: pkg/man/findMutations.Rd
===================================================================
--- pkg/man/findMutations.Rd 2012-11-20 12:01:26 UTC (rev 1054)
+++ pkg/man/findMutations.Rd 2012-11-20 17:08:51 UTC (rev 1055)
@@ -1,49 +0,0 @@
-\encoding{UTF-8}
-\name{findMutations}
-\alias{findMutations}
-\alias{findMutations.DNAbin}
-\title{Identify mutations between DNA sequences}
-\description{
- This function compares pairs of aligned DNA sequences and identify
- mutations (position and nature).\cr
-
- The function \code{findMutations} is a generic, but the only method
- implemented in adegenet so far is for \code{\link[ape]{DNAbin}}
- objects.
-}
-\usage{
-findMutations(x, pairs=NULL, \dots)
-
-\method{findMutations}{DNAbin}(x, pairs=NULL, \dots)
-
-}
-\arguments{
- \item{x}{a \code{DNAbin} object containing aligned sequences, as a matrix.}
- \item{pairs}{a matrix with two columns specifying which
- sequences to compare. Mutations will be identified from the first
- column to the second. Any way of refering to the rows of \code{x} is
- acceptable. If \code{NULL}, all pairs are considered.}
-}
-\value{
- A named list indicating the mutations from one sequence to another.
- For each comparison, a three-column matrix is provided, corresponding
- to the nucleotides in first and second sequence, and a summary of the
- mutation provided as:
- [position]:[nucleotide in first sequence]->[nucleotide in second sequence].
-}
-\seealso{
- The \code{\link{fasta2DNAbin}} to read fasta alignments with minimum
- RAM use.
-}
-\author{
- Thibaut Jombart \email{t.jombart at imperial.ac.uk}.
- }
-\examples{
-\dontrun{
-if(require(ape)){
-data(woodmouse)
-findMutations(woodmouse[1:5,])
-findMutations(woodmouse, pairs=cbind(c(1,1),c(2,3)))
-}
-}
-}
Modified: pkg/man/gengraph.Rd
===================================================================
--- pkg/man/gengraph.Rd 2012-11-20 12:01:26 UTC (rev 1054)
+++ pkg/man/gengraph.Rd 2012-11-20 17:08:51 UTC (rev 1055)
@@ -29,16 +29,21 @@
\usage{
gengraph(x, \dots)
-\method{gengraph}{matrix}(x, cutoff=NULL, ngrp=NULL, computeAll=FALSE, plot=TRUE, show.graph=TRUE, col.pal=funky, \dots)
+\method{gengraph}{matrix}(x, cutoff=NULL, ngrp=NULL, computeAll=FALSE,
+plot=TRUE, show.graph=TRUE, col.pal=funky, truenames=TRUE, \dots)
-\method{gengraph}{dist}(x, cutoff=NULL, ngrp=NULL, computeAll=FALSE, plot=TRUE, show.graph=TRUE, col.pal=funky, \dots)
+\method{gengraph}{dist}(x, cutoff=NULL, ngrp=NULL, computeAll=FALSE,
+plot=TRUE, show.graph=TRUE, col.pal=funky, truenames=TRUE, \dots)
-\method{gengraph}{genind}(x, cutoff=NULL, ngrp=NULL, computeAll=FALSE, plot=TRUE, show.graph=TRUE, col.pal=funky, \dots)
+\method{gengraph}{genind}(x, cutoff=NULL, ngrp=NULL, computeAll=FALSE,
+plot=TRUE, show.graph=TRUE, col.pal=funky, truenames=TRUE, \dots)
\method{gengraph}{genpop}(x, cutoff=NULL, ngrp=NULL, computeAll=FALSE,
- plot=TRUE, show.graph=TRUE, col.pal=funky, method=1, \dots)
+ plot=TRUE, show.graph=TRUE, col.pal=funky, method=1,
+ truenames=TRUE, \dots)
-\method{gengraph}{DNAbin}(x, cutoff=NULL, ngrp=NULL, computeAll=FALSE, plot=TRUE, show.graph=TRUE, col.pal=funky, \dots)
+\method{gengraph}{DNAbin}(x, cutoff=NULL, ngrp=NULL, computeAll=FALSE,
+plot=TRUE, show.graph=TRUE, col.pal=funky, truenames=TRUE, \dots)
}
\arguments{
@@ -64,6 +69,9 @@
between populations; values from 1 to 5 are passed to the function
\code{dist.genpop}; 6 corresponds to pairwise Fst; other values are
not supported.}
+ \item{truenames}{a logical indicating whether original labels should
+ be used for plotting (TRUE), as opposed to indices of sequences
+ (FALSE).}
\item{\dots}{further arguments to be used by other functions;
currently not used.}
}
Copied: pkg/man/mutations.Rd (from rev 1052, pkg/man/findMutations.Rd)
===================================================================
--- pkg/man/mutations.Rd (rev 0)
+++ pkg/man/mutations.Rd 2012-11-20 17:08:51 UTC (rev 1055)
@@ -0,0 +1,82 @@
+\encoding{UTF-8}
+\name{findMutations}
+\alias{findMutations}
+\alias{findMutations.DNAbin}
+\alias{graphMutations}
+\alias{graphMutations.DNAbin}
+\title{Identify mutations between DNA sequences}
+\description{
+ The function \code{findMutations} identifies mutations (position and
+ nature) of pairs of aligned DNA sequences. The function
+ \code{graphMutations} does the same thing but plotting mutations on a
+ directed graph.\cr
+
+ Both functions are generics, but the only methods implemented in
+ adegenet so far is for \code{\link[ape]{DNAbin}} objects.
+}
+\usage{
+findMutations(\dots)
+
+\method{findMutations}{DNAbin}(x, from=NULL, to=NULL, allcomb=TRUE, \dots)
+
+graphMutations(\dots)
+
+\method{graphMutations}{DNAbin}(x, from=NULL, to=NULL, allcomb=TRUE, plot=TRUE,
+ curved.edges=TRUE, \dots)
+
+}
+\arguments{
+ \item{x}{a \code{DNAbin} object containing aligned sequences, as a matrix.}
+ \item{from}{a vector indicating the DNA sequences from which mutations
+ should be found. If \code{NULL}, all sequences are considered (i.e.,
+ \code{1:nrow(x)}).}
+ \item{to}{a vector indicating the DNA sequences to which mutations
+ should be found. If \code{NULL}, all sequences are considered (i.e.,
+ \code{1:nrow(x)}).}
+ \item{allcomb}{a logical indicating whether all combinations of
+ sequences (from and to) should be considered (TRUE, default), or not
+ (FALSE).}
+ \item{plot}{a logical indicating whether the graph should be plotted.}
+ \item{curved.edges}{a logical indicating whether the edges of the
+ graph should be curved.}
+ \item{\dots}{further arguments to be passed to other methods. Used in
+ \code{graphMutations} where it is passed to the plot method for
+ \code{igraph} objects.}
+}
+\value{
+ For \code{findMutations}, a named list indicating the mutations from
+ one sequence to another. For each comparison, a three-column matrix is
+ provided, corresponding to the nucleotides in first and second
+ sequence, and a summary of the mutation provided as:
+ [position]:[nucleotide in first sequence]->[nucleotide in second
+ sequence].
+
+ For \code{graphMutations}, a graph with the class \code{igraph}.
+}
+\seealso{
+ The \code{\link{fasta2DNAbin}} to read fasta alignments with minimum
+ RAM use.
+}
+\author{
+ Thibaut Jombart \email{t.jombart at imperial.ac.uk}.
+ }
+\examples{
+\dontrun{
+data(woodmouse)
+
+## mutations between first 3 sequences
+findMutations(woodmouse[1:3,])
+
+## mutations from the first to sequences 2 and 3
+findMutations(woodmouse[1:3,], from=1)
+
+## same, graphical display
+g <- graphMutations(woodmouse[1:3,], from=1)
+
+## some manual checks
+as.character(woodmouse)[1:3,35]
+as.character(woodmouse)[1:3,36]
+as.character(woodmouse)[1:3,106]
+
+}
+}
More information about the adegenet-commits
mailing list