[adegenet-commits] r1024 - misc pkg/R pkg/man
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Mon Jul 16 17:09:56 CEST 2012
Author: jombart
Date: 2012-07-16 17:09:56 +0200 (Mon, 16 Jul 2012)
New Revision: 1024
Added:
misc/testExpl.R
Modified:
pkg/R/gengraph.R
pkg/R/haploGen.R
pkg/man/gengraph.Rd
pkg/man/haploGen.Rd
pkg/man/read.snp.Rd
pkg/man/seploc.Rd
pkg/man/simOutbreak.Rd
Log:
New functions checked, doc OK, check OK.
Added: misc/testExpl.R
===================================================================
--- misc/testExpl.R (rev 0)
+++ misc/testExpl.R 2012-07-16 15:09:56 UTC (rev 1024)
@@ -0,0 +1,10 @@
+testExamples <- function(dir="~/dev/adegenet/pkg"){
+ setwd(dir)
+ setwd("man")
+ toRead <- dir()
+ for(e in toRead){
+ txt <- readLines(e)
+ temp <- txt[grep("alias",txt)]
+
+ }
+}
Modified: pkg/R/gengraph.R
===================================================================
--- pkg/R/gengraph.R 2012-07-16 09:10:02 UTC (rev 1023)
+++ pkg/R/gengraph.R 2012-07-16 15:09:56 UTC (rev 1024)
@@ -117,12 +117,12 @@
############
## GENIND ##
############
-gengraph.dist <- function(x, cutoff=NULL, ncut=NULL, computeAll=FALSE, plot=TRUE, col.pal=funky, ...){
+gengraph.dist <- function(x, cutoff=NULL, ngrp=NULL, computeAll=FALSE, plot=TRUE, show.graph=TRUE, col.pal=funky, ...){
## CHECKS ##
if(!require("igraph")) stop("igraph is required")
## USE MATRIX METHOD ##
- res <- gengraph(as.matrix(x), cutoff=cutoff, ncut=ncut, computeAll=computeAll, plot=plot, col.pal=col.pal, ...)
+ res <- gengraph(as.matrix(x), cutoff=cutoff, ngrp=ngrp, computeAll=computeAll, plot=plot, show.graph=show.graph, col.pal=col.pal, ...)
return(res)
} # end gengraph.dist
@@ -135,7 +135,7 @@
############
## GENIND ##
############
-gengraph.genind <- function(x, cutoff=NULL, ncut=NULL, computeAll=FALSE, plot=TRUE, col.pal=funky, ...){
+gengraph.genind <- function(x, cutoff=NULL, ngrp=NULL, computeAll=FALSE, plot=TRUE, show.graph=TRUE, col.pal=funky, ...){
## CHECKS ##
if(!require("igraph")) stop("igraph is required")
@@ -144,7 +144,7 @@
D <- (1-propShared(x))*nLoc(x)*ploidy(x)
## USE MATRIX METHOD ##
- res <- gengraph(D, cutoff=cutoff, ncut=ncut, computeAll=computeAll, plot=plot, col.pal=col.pal, ...)
+ res <- gengraph(D, cutoff=cutoff, ngrp=ngrp, computeAll=computeAll, plot=plot, show.graph=show.graph, col.pal=col.pal, ...)
return(res)
} # end gengraph.genind
@@ -158,7 +158,7 @@
############
## GENPOP ##
############
-gengraph.genpop <- function(x, cutoff=NULL, ncut=NULL, computeAll=FALSE, plot=TRUE, col.pal=funky, method=1, ...){
+gengraph.genpop <- function(x, cutoff=NULL, ngrp=NULL, computeAll=FALSE, plot=TRUE, show.graph=TRUE, col.pal=funky, method=1, ...){
## CHECKS ##
if(!require("igraph")) stop("igraph is required")
@@ -171,7 +171,7 @@
}
## USE MATRIX METHOD ##
- res <- gengraph(D, cutoff=cutoff, ncut=ncut, computeAll=computeAll, plot=plot, col.pal=col.pal, ...)
+ res <- gengraph(D, cutoff=cutoff, ngrp=ngrp, computeAll=computeAll, plot=plot, show.graph=show.graph, col.pal=col.pal, ...)
return(res)
} # end gengraph.genpop
@@ -184,7 +184,7 @@
############
## DNABIN ##
############
-gengraph.DNAbin <- function(x, cutoff=NULL, ncut=NULL, computeAll=FALSE, plot=TRUE, col.pal=funky, ...){
+gengraph.DNAbin <- function(x, cutoff=NULL, ngrp=NULL, computeAll=FALSE, plot=TRUE, show.graph=TRUE, col.pal=funky, ...){
## CHECKS ##
if(!require("igraph")) stop("igraph is required")
if(!require("ape")) stop("ape is required")
@@ -193,7 +193,7 @@
D <- as.matrix(round(dist.dna(x,model="raw", pairwise.deletion = TRUE)*ncol(x)))
## USE MATRIX METHOD ##
- res <- gengraph(D, cutoff=cutoff, ncut=ncut, computeAll=computeAll, plot=plot, col.pal=col.pal, ...)
+ res <- gengraph(D, cutoff=cutoff, ngrp=ngrp, computeAll=computeAll, plot=plot, show.graph=show.graph, col.pal=col.pal, ...)
return(res)
} # end gengraph.DNAbin
Modified: pkg/R/haploGen.R
===================================================================
--- pkg/R/haploGen.R 2012-07-16 09:10:02 UTC (rev 1023)
+++ pkg/R/haploGen.R 2012-07-16 15:09:56 UTC (rev 1024)
@@ -10,7 +10,7 @@
##
haploGen <- function(seq.length=1e4, mu.transi=1e-4, mu.transv=mu.transi/2, t.max=20,
gen.time=function(){1+rpois(1,0.5)},
- repro=function(){rpois(1,1.5)}, max.nb.haplo=1e3,
+ repro=function(){rpois(1,1.5)}, max.nb.haplo=200,
geo.sim=FALSE, grid.size=10, lambda.xy=0.5,
mat.connect=NULL,
ini.n=1, ini.xy=NULL){
@@ -20,16 +20,16 @@
## HANDLE ARGUMENTS ##
- ## if numeric vector, taken as proba for t=0,1,2,...(length-1)
+ ## if numeric value, make it a function
if(is.numeric(gen.time)){
- gen.time.val <- gen.time/sum(gen.time)
- gen.time <- function(){sample(0:(length(repro.val)-1), size=1, prob=gen.time.val)}
+ gen.time.val <- gen.time[1]
+ gen.time <- function(){return(gen.time.val)}
}
- ## if numeric vector, taken as proba for ndesc=0,1,2,...(length-1)
+ ## if numeric value, make it a function
if(is.numeric(repro)){
- repro.val <- repro/sum(repro)
- repro <- function(){sample(0:(length(repro.val)-1),size=1,prob=repro.val)}
+ repro.val <- repro[1]
+ repro <- function(){return(repro.val)}
}
Modified: pkg/man/gengraph.Rd
===================================================================
--- pkg/man/gengraph.Rd 2012-07-16 09:10:02 UTC (rev 1023)
+++ pkg/man/gengraph.Rd 2012-07-16 15:09:56 UTC (rev 1024)
@@ -24,7 +24,7 @@
- \code{dist} \cr
- \code{\linkS4class{genind}} objects (genetic markers, individuals)\cr
- \code{\linkS4class{genpop}} objects (genetic markers, populations)\cr
- - \code{\linkS4class{DNAbin}} objects (DNA sequences)
+ - \code{\link[ape]{DNAbin}} objects (DNA sequences)
}
\usage{
gengraph(x, \dots)
@@ -36,7 +36,7 @@
\method{gengraph}{genind}(x, cutoff=NULL, ngrp=NULL, computeAll=FALSE, plot=TRUE, show.graph=TRUE, col.pal=funky, \dots)
\method{gengraph}{genpop}(x, cutoff=NULL, ngrp=NULL, computeAll=FALSE,
- plot=TRUE, show.graph=TRUE, method=1, col.pal=funky, \dots)
+ plot=TRUE, show.graph=TRUE, col.pal=funky, method=1, \dots)
\method{gengraph}{DNAbin}(x, cutoff=NULL, ngrp=NULL, computeAll=FALSE, plot=TRUE, show.graph=TRUE, col.pal=funky, \dots)
@@ -77,17 +77,13 @@
\item{cutoff}{the value used as a cutoff point}
\item{col}{the color used to plot each group.}
}
-\references{
-
-}
\seealso{
The \code{\link[igraph]{igraph}} package.
}
\author{
- Thibaut Jombart \email{t.jombart at imperial.ac.uk}
- Anne Cori
- Christophe Fraser
-}
+ Original idea by Anne Cori and Christophe Fraser.
+ Implementation by Thibaut Jombart \email{t.jombart at imperial.ac.uk}.
+ }
\examples{
\dontrun{
dat <- haploGen()
Modified: pkg/man/haploGen.Rd
===================================================================
--- pkg/man/haploGen.Rd 2012-07-16 09:10:02 UTC (rev 1023)
+++ pkg/man/haploGen.Rd 2012-07-16 15:09:56 UTC (rev 1024)
@@ -6,21 +6,16 @@
\alias{as.POSIXct.haploGen}
\alias{seqTrack.haploGen}
\alias{haploGen-class}
-% \alias{seqTrackG.haploGen}
-% \alias{optimize.seqTrack.haploGen}
\alias{as.seqTrack.haploGen}
\alias{as.igraph.haploGen}
\alias{plotHaploGen}
\alias{sample.haploGen}
-%\alias{as,haploGen,graphNEL-method}
-%\alias{coerce,haploGen,graphNEL-method}
-%\alias{as,haploGen,graphNEL-method}
\title{Simulation of genealogies of haplotypes}
\description{
The function \code{haploGen} implements simulations of genealogies of
- haplotypes. This forward-time, individual-based simulation tool allow
+ haplotypes. This forward-time, individual-based simulation tool allows
haplotypes to replicate and mutate according to specified parameters,
- and keeps track of entire genealogies.
+ and keeps track of their genealogy.
Simulations can be spatially explicit or not (see \code{geo.sim}
argument). In the first case, haplotypes are assigned to locations on
@@ -34,13 +29,17 @@
available to print, plot, subset, sample or convert \code{haploGen}
objects. A seqTrack method is also provided for analysing
\code{haploGen} objects.
+
+ Note that for simulation of outbreaks, the new tool \code{\link{simOutbreak}} should
+ be used.
}
\usage{
-haploGen(seq.length=10000, mu=0.0001, t.max=20,
- gen.time=function(){round(rnorm(1,5,1))},
- repro=function(){round(rnorm(1,2,1))}, max.nb.haplo=1e3,
- geo.sim=TRUE, grid.size=5, lambda.xy=0.5,
- mat.connect=NULL, ini.n=1, ini.xy=NULL)
+haploGen(seq.length=1e4, mu.transi=1e-4, mu.transv=mu.transi/2, t.max=20,
+ gen.time=function(){1+rpois(1,0.5)},
+ repro=function(){rpois(1,1.5)}, max.nb.haplo=200,
+ geo.sim=FALSE, grid.size=10, lambda.xy=0.5,
+ mat.connect=NULL,
+ ini.n=1, ini.xy=NULL)
\method{print}{haploGen}(x, \dots)
\method{[}{haploGen}(x, i, j, drop=FALSE)
\method{labels}{haploGen}(object, \dots)
@@ -55,9 +54,10 @@
\arguments{
\item{seq.length}{an integer indicating the length of the simulated
haplotypes, in number of nucleotides.}
- \item{mu}{the mutation rate, in number of mutation per site and per
- time unit. Can be a (fixed) number or a function returning a number
- (then called for each replication event).}
+ \item{mu.transi}{the rate of transitions, in number of mutation per site and per
+ time unit.}
+ \item{mu.transv}{the rate of transversions, in number of mutation per site and per
+ time unit.}
\item{t.max}{an integer indicating the maximum number of time units to
run the simulation for.}
\item{gen.time}{an integer indicating the generation time, in number
@@ -72,7 +72,7 @@
simulations. If this number is exceeded, the genealogy is prunded to as
to keep this number of haplotypes.}
\item{geo.sim}{a logical stating whether simulations should be
- spatially explicit (TRUE, default) or not (FALSE). Spatially-explicit
+ spatially explicit (TRUE) or not (FALSE, default). Spatially-explicit
simulations are slightly slower than their non-spatial counterpart.}
\item{grid.size}{the size of the square grid of possible locations for
spatial simulations. The total number of locations will be this number
@@ -154,35 +154,41 @@
See the respective vignettes for more information on using these packages.
- % === Converting haploGen objects to graphs ===\cr
- % \code{haploGen} objects can be converted to \code{graphNEL-class}
- % objects, which can in turn be plotted and manipulated using classical
- % graph tools. Simply use 'as(x, "graphNEL")' where 'x' is a
- % \code{haploGen} object. This functionality requires the \code{graph}
- % package (see 'details').
+ === Converting haploGen objects to graphs ===\cr
+ \code{haploGen} objects can be converted to \code{igraph}
+ objects (package \code{igraph}), which can in turn be plotted and manipulated using classical
+ graph tools. Simply use 'as.igraph(x)' where 'x' is a
+ \code{haploGen} object. This functionality requires the \code{igraph}
+ package.
}
+\seealso{
+ \code{\link{simOutbreak}} for simulating disease outbreaks under a
+ realistic epidemiological model.
+}
\examples{
\dontrun{
if(require(ape)){
## PERFORM SIMULATIONS
-x <- haploGen(repro=2)
+x <- haploGen(geo.sim=TRUE)
x
## PLOT SPATIAL SPREAD
plotHaploGen(x, bg="white")
-title("Spatial dispersion of the haplotypes")
+title("Spatial dispersion")
-% ## PLOT GENEALOGY
-% if(require(graph) & require(Rgraphviz)){
-% g=as(x, "graphNEL")
-% g
-% renderGraph(layoutGraph(g))
-% }
-
## USE SEQTRACK RECONSTRUCTION
x.recons <- seqTrack(x)
mean(x.recons$ances==x$ances, na.rm=TRUE) # proportion of correct reconstructions
+
+
+if(require(igraph)){
+g <- as.igraph(x)
+g
+plot(g)
+plot(g, vertex.size=0)
+
}
}
}
+}
Modified: pkg/man/read.snp.Rd
===================================================================
--- pkg/man/read.snp.Rd 2012-07-16 09:10:02 UTC (rev 1023)
+++ pkg/man/read.snp.Rd 2012-07-16 15:09:56 UTC (rev 1024)
@@ -79,6 +79,7 @@
}
\author{Thibaut Jombart \email{t.jombart at imperial.ac.uk} }
\examples{
+\dontrun{
## show the example file ##
## this is the path to the file:
system.file("files/exampleSnpDat.snp",package="adegenet")
@@ -86,6 +87,7 @@
## show its content:
file.show(system.file("files/exampleSnpDat.snp",package="adegenet"))
+
## read the file
obj <-
read.snp(system.file("files/exampleSnpDat.snp",package="adegenet"), chunk=2)
@@ -95,4 +97,5 @@
alleles(obj)
locNames(obj)
}
+}
\keyword{manip}
Modified: pkg/man/seploc.Rd
===================================================================
--- pkg/man/seploc.Rd 2012-07-16 09:10:02 UTC (rev 1023)
+++ pkg/man/seploc.Rd 2012-07-16 15:09:56 UTC (rev 1024)
@@ -49,6 +49,7 @@
\author{Thibaut Jombart \email{t.jombart at imperial.ac.uk} }
\seealso{\code{\link{seppop}}, \code{\link{repool}}}
\examples{
+\dontrun{
## example on genind objects
data(microbov)
@@ -73,4 +74,5 @@
foo # note the different block sizes
glPlot(foo[[1]])
}
+}
\keyword{manip}
\ No newline at end of file
Modified: pkg/man/simOutbreak.Rd
===================================================================
--- pkg/man/simOutbreak.Rd 2012-07-16 09:10:02 UTC (rev 1023)
+++ pkg/man/simOutbreak.Rd 2012-07-16 15:09:56 UTC (rev 1024)
@@ -42,6 +42,8 @@
instance, \code{i=1:3} will retain only the first three haplotypes of the
outbreak. \code{j} and \code{drop} are only provided for compatibility,
but not used.}
+ \item{y}{present for compatibility with the generic 'plot'
+method. Currently not used.}
\item{cex}{a size factor for the vertices of the plotted graph.}
\item{col}{the color of the vertices of the plotted graph.}
\item{label}{the labels of the vertices of the plotted graph.}
More information about the adegenet-commits
mailing list