haploGen
implements simulations of genealogies of
haplotypes. This forward-time, individual-based simulation tool allow
haplotypes to replicate and mutate according to specified parameters,
and keeps track of entire genealogies. Simulations can be spatially explicit or not (see geo.sim
argument). In the first case, haplotypes are assigned to locations on
a regular grip. New haplotypes disperse from their ancestor's location
according to a random Poisson diffusion, or alternatively according to
a pre-specified migration scheme. This tool does not allow for
simulating selection or linkage disequilibrium.
Produced objects are lists with the class haploGen
; see 'value'
section for more information on this class. Other functions are
available to print, plot, subset, sample or convert haploGen
objects. A seqTrack method is also provided for analysing
haploGen
objects.
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)
## S3 method for class 'haploGen':
print(x, \dots)
## S3 method for class 'haploGen':
[(x, i, j, drop=FALSE)
## S3 method for class 'haploGen':
labels(object, \dots)
## S3 method for class 'haploGen':
as.POSIXct(x, tz="", origin=as.POSIXct("2000/01/01"), ...)
## S3 method for class 'haploGen':
seqTrack(x, best=c("min","max"), prox.mat=NULL, ...)
as.seqTrack.haploGen(x)
plotHaploGen(x, annot=FALSE, date.range=NULL, col=NULL, bg="grey", add=FALSE, ...)
sample.haploGen(x, n)
## S3 method for class 'haploGen,graphNEL':
coerce(from, to, strict=TRUE)
mat.connect[i,j]
indicates the
probability, being in 'i', to migrate to 'j'. The rows of this matrix
thus sum to 1. It has as many rows and columns as thaploGen
objects.i
is a vector used for subsetting the object. For
instance, i=1:3
will retain only the first three haplotypes of the
genealogy. j
and drop
are only provided for compatibility,
but not used.plotSeqTrack
.haploGen
object into a graphNEL-class
.as.POSIXct
(see ?as.POSIXct)as
generic
function, but not used in the conversion. See setAs
for
more information.haploGen
objects are lists containing the following slots:
- seq: DNA sequences in the DNAbin matrix format
- dates: dates of appearance of the haplotypes
- ances: a vector of integers giving the index of each haplotype's
ancestor
- id: a vector of integers giving the index of each haplotype
- xy: (optional) a matrix of spatial coordinates of haplotypes
- call: the matched call
=== misc functions ===
- as.POSIXct: returns a vector of dates with POSIXct format
- labels: returns the labels of the haplotypes
- as.seqTrack: returns a seqTrack object. Note that this object is not a
proper seqTrack analysis, but just a format conversion convenient for
plotting haploGen
objects.
haploGen
objects. To install this package,
simply type:
install.packages("ape")
- for various purposes including plotting, converting genealogies to
graphs (graphNEL-class
class) can be useful. This requires the
packages graph, and possibly Rgraphviz for plotting. These packages are
not on CRAN, but on Bioconductor. To install them, use:
source("http://bioconductor.org/biocLite.R")
biocLite("graph")
biocLite("Rgraphviz")
See the respective vignettes for more information on using these packages.
=== Converting haploGen objects to graphs ===
haploGen
objects can be converted to graphNEL-class
objects, which can in turn be plotted and manipulated using classical
graph tools. Simply use 'as(x, "graphNEL")' where 'x' is a
haploGen
object. This functionality requires the graph
package (see 'details').
if(require(ape)){
## PERFORM SIMULATIONS
x <- haploGen(repro=2)
x
## PLOT SPATIAL SPREAD
plotHaploGen(x, bg="white")
title("Spatial dispersion of the haplotypes")
## 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
}
Run the code above in your browser using DataLab